无法打开文件来阅读PHP

Val*_*ian 0 php

我试图打开一个文件,但由于某种原因我甚至不能文件存在,甚至有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)

为什么我不能打开文件?我的错误在哪里?

谢谢

You*_*nse 6

我的错误在哪里?

您没有正确设置错误报告.有两件事需要记住.

  1. 错误报告级别.由error_reportingini指令或error_reporting()功能设置.应该总是在E_ALL或更高.

  2. 错误消息目的地.

    • 开发服务器上它应该显示
    • 在实时服务器上它应该是一个日志文件

因此,要快速解决方案,请将这两行放在脚本的顶部

error_reporting(E_ALL);
ini_set('display_errors',1);
Run Code Online (Sandbox Code Playgroud)

但后来将这些设置设置为整个站点的永久设置(根据服务器状态)

一旦你完成它,你将得到你的问题的答案.
请注意,你不会仅仅从堆栈花的猜测中猜出,而是从系统本身对问题的准确解释.