【发布时间】:2015-07-09 10:42:34
【问题描述】:
我已配置文件下载,但在某些情况下无法下载文件。 因为 file_exist 不正确,所以 php 代码会死掉并返回给我定义的错误消息。
为什么在目录中有逗号 OR 空格时下载可以正常工作, 但失败了 BOTH 一个 逗号 后跟一个 空格?
下载错误的文件:
$the_download = "/share/Multimedia/Library1/John, Doe/test/cover.jpg";
下载成功的文件:
$the_download = "/share/Multimedia/Library1/John,Doe/test/cover.jpg";
$the_download = "/share/Multimedia/Library1/John Doe/test/cover.jpg";
代码:
$the_filename = "somefilename.jpg";
if (file_exists($the_download)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($the_filename));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($the_download));
flush();
readfile($the_download);
exit;
}
else die("File not found<br>" . $the_download);
【问题讨论】:
-
什么错误信息?
-
错误消息:找不到文件 35,如 else die 语句中所示。脚本死亡并向我显示文件名。当我在 " " 中本地查找时,文件名非常好
标签: php file-exists