php - HTTP 头文件未完全下载

标签 php file http download header

我正在尝试下载带有 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/

相关文章:

java - 在 Linux 中将 Java URL 转换为有效的文件路径

http - 如何在不发送响应的情况下终止 http 请求?

通过 HTTP 克隆 Git

php - CSS 样式表中的 If ... else 条件语句处理为 PHP

php - 将月份编号转换为月份简称

c++ - 从文件读取时无法使用 getline

http - 使用go http client Do方法时,httpResponse和error不能同时为nil吗?

php - UTF-8 和 HTML 实体有什么区别?

php - 可排序数据 PHP MYSQL

java - 创建从资源路径到 jar 文件中图像的文件对象