我试图打开一个文件,但由于某种原因我甚至不能文件存在,甚至有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>";
}
Run Code Online (Sandbox Code Playgroud)
结果是:
File size is 1252121
The file /opt/lampp/htdocs/a.pdf exist
Could not open the file !
Run Code Online (Sandbox Code Playgroud)
为什么我不能打开文件?我的错误在哪里?
谢谢
我的错误在哪里?
您没有正确设置错误报告.有两件事需要记住.
错误报告级别.由error_reportingini指令或error_reporting()功能设置.应该总是在E_ALL或更高.
错误消息目的地.
因此,要快速解决方案,请将这两行放在脚本的顶部
error_reporting(E_ALL);
ini_set('display_errors',1);
Run Code Online (Sandbox Code Playgroud)
但后来将这些设置设置为整个站点的永久设置(根据服务器状态)
一旦你完成它,你将得到你的问题的答案.
请注意,你不会仅仅从堆栈花的猜测中猜出,而是从系统本身对问题的准确解释.