【发布时间】:2016-06-01 10:52:28
【问题描述】:
我收到一个错误。我正在尝试阅读附件。它在大多数文件上都可以正常工作,但在少数文件中我得到了这个错误。这些文件具有相同的格式,并且它尝试读取的位置是正确的。我已经在 windows 资源管理器上测试过了。这是我正在阅读的方式:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $filename .'"');
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: ' . filesize($attachment_location));
ob_clean();
flush();
readfile($attachment_location);
exit();
这是我得到的错误
警告:readfile(C:\Users\Public\asdgasd\4sf3\Suppliers\saf342\Files\Revit\2016\Seinätikas.rfa): failed to open stream: No such file or directory in C:\xampp\htdocs\web\downloadattachment.php on line 58
【问题讨论】:
-
它清楚地表明你的文件系统中没有这样的文件。如果存在这样的文件,请在调用 readfile() 之前检查它。
-
我确实检查过它确实存在。
-
不,我的意思是你要做这样的事情:var_dump(file_exists($attachment_location));这会告诉你php是否看到这个文件。
-
响应是:bool(false) 所以php看不到。
-
元音变音、Windows 和 PHP?致命的组合。 :)