php – readfile无法正常工作

我正试图通过我的服务器下载文件,通过流式传输下载.

这是我的脚本:

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=http://user:pass@example.com/file.bin';
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $r[2]);
ob_clean();
flush();
readfile($fileName);
exit;

example.com不是我真正使用的,我只是不想显示真正的URL. :)当我在我的网络浏览器中访问此文件时,没有出现下载提示,也没有任何反应. $r [2]是文件的内容长度(以字节为单位),$fileName与附件标题中使用的URL相同.我真的不知道我做错了什么.

解决方法:

ReadFile的();需要机器上文件的绝对路径而不是网址.

例如/home/person/file.exe

上一篇:php – 如何读取codeigniter文件夹之外的文件


下一篇:python – 如何定义要从文件读入的行的长度