1

I am trying to download the file with http header but it will not download completly. The uploaded file size is 1 MB and the file download with my code 336 byte size only.

I am trying with below code

$attachment_location= "filename";
$filePath= "$siteURL/foldername/filename";
$file_content       = file_get_contents($filePath);
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$attachment_location\"");
echo $file_content;
Narayan
  • 1,670
  • 1
  • 19
  • 37
  • That question may answer yours https://stackoverflow.com/questions/386845/http-headers-for-file-downloads – mkungla May 29 '17 at 09:34

1 Answers1

0

I have solved this issue by just changing the filepath remove the path with SiteURL and provide the path from folder. Check code below,

$attachment_location= "filename";
$filePath= "foldername/filename";
$file_content       = file_get_contents($filePath);
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$attachment_location\"");
echo $file_content;
Narayan
  • 1,670
  • 1
  • 19
  • 37