2017-05-29 103 views
1

我試圖用http頭下載文件,但它不會完全下載。上傳的文件size is 1 MB和文件僅用我的代碼336 byte大小下載。HTTP頭文件沒有完全下載

我用下面的代碼

$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; 
+0

該問題可能會回答你的問題https://stackoverflow.com/questions/386845/http-headers-for-file-downloads –

回答

0

我已經只是改變了文件路徑刪除路徑與SiteURL,並提供從文件夾的路徑來解決這個問題嘗試。檢查下面的代碼,

$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;