读取文件无法正常工作 [英] readfile not working properly
问题描述
我正在尝试通过我的服务器通过流式下载将文件下载给我.
I'm trying to download a file through my server to me, by streaming the download.
这是我的脚本:
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 相同的 URL.我真的不知道我做错了什么.
example.com isn't what I'm really using, I just didn't want to show the real URL. :) When I go to this file in my web browser a download prompt does not come up and nothing happens. $r[2]
is the content length in bytes of the file and $fileName
is the same URL as used in the attachment header. I really don't know what I'm doing wrong.
推荐答案
readfile();需要机器上文件的绝对路径而不是url.
readfile(); needs the absolute path of the file on the machine rather than a url.
例如/home/person/file.exe
e.g. /home/person/file.exe
这篇关于读取文件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!