我试图打开一个文件,但由于某种原因我不能,即使文件在那里,甚至有777权限。代码如下:
$fileatt = "/opt/lampp/htdocs/a.pdf";
echo "File size is ".filesize($fileatt)."<br>";
if (file_exists($fileatt)) {
echo "The file ".$fileatt." exist <br>";
$file = fopen($fileatt, ‘rb’);
if ($file == false) {
echo "Could not open the file !";
}
} else {
echo "The file ".$fileatt." does NOT exist <br>";
}
结果是:
File size is 1252121
The file /opt/lampp/htdocs/a.pdf exist
Could not open the file !
为什么我打不开文件?我错在哪里?
谢谢
我错在哪里?
您没有正确设置错误报告。有两件事要记住。
-
错误报告级别。由
error_reporting
ini指令或error_reporting()
函数设置。 -
错误消息目的地。
- 在开发服务器上应该显示
- 在活动服务器上,它应该是一个日志文件
error_reporting(E_ALL);
ini_set('display_errors',1);
但后来将这些设置设置为整个站点的永久设置(根据服务器状态)
一旦你做了这件事,你就有了问题的答案。请注意,您将得到的不仅仅是来自stackoverflowers同伴的猜测,而是来自系统本身的对事件的确切解释。