我正在尝试下载带有 http header 的文件,但它不会下载完整。上传的文件大小为 1 MB
,下载的文件只有我的代码 336 字节
大小。
我正在尝试使用下面的代码
$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;
最佳答案
我已经解决了这个问题,只需更改 filepath 删除带有 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;
关于php - HTTP 头文件未完全下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44238731/