fopen 的详细错误

发布于 2024-08-26 05:00:54 字数 199 浏览 3 评论 0原文

我正在使用 fopen 从文件中读取

$fh = fopen($path, 'r') or die('Could not open file');

现在我不断收到错误无法打开文件。我检查了文件路径,甚至将文件的权限更改为777。有没有办法获得详细的错误报告,解释为什么文件无法打开,类似于mysql_error()?

I'm using fopen to read from a file

$fh = fopen($path, 'r') or die('Could not open file');

Now I contantly get error Could not open file. I checked the file path and even changed the permissions of the file to 777. Is there a way I can get a detailed error report as why the file can't be opened similar to mysql_error()?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

妖妓 2024-09-02 05:00:54

打开错误报告,或者,在生产环境中(从 PHP 5.2.0 开始)您还应该能够使用 error_get_last()

Turn on error reporting, or, in a production environment (from PHP 5.2.0 onwards) you should also be able to use error_get_last().

贩梦商人 2024-09-02 05:00:54

对于 5.2 之前的 php 版本(缺少 error_get_last()),您可以使用

ini_set('track_errors', 1);
$fh = fopen('lalala', 'r');
if ( !$fh ) {
  echo 'fopen failed. reason: ', $php_errormsg;
}

另请参阅:http://de.php.net/reserved.variables.phperrormsg

For php versions prior to 5.2 (lacking error_get_last()) you can use track_errors.

ini_set('track_errors', 1);
$fh = fopen('lalala', 'r');
if ( !$fh ) {
  echo 'fopen failed. reason: ', $php_errormsg;
}

see also: http://de.php.net/reserved.variables.phperrormsg

裂开嘴轻声笑有多痛 2024-09-02 05:00:54

是的。
PHP 为您提供了详细的错误消息。
您只需将其打开即可。

要在屏幕上显示它,请在脚本顶部添加以下两行:

ini_set('display_errors',1);
error_reporting(E_ALL);

或者如果您希望将其记录下来,

ini_set('log_errors',1);
ini_set('display_errors',0);
error_reporting(E_ALL);

另请注意,使用 die() 是非常糟糕的做法。

Yes.
PHP has detailed error message for you.
You just have to turn it on.

To dislay it on the screen add these 2 lines at the top of the script:

ini_set('display_errors',1);
error_reporting(E_ALL);

Or if you want it to be logged instead,

ini_set('log_errors',1);
ini_set('display_errors',0);
error_reporting(E_ALL);

Also note that using die() is very bad practice.

姐不稀罕 2024-09-02 05:00:54
$fh = fopen($path, 'r') or  die (error_get_last());
$fh = fopen($path, 'r') or  die (error_get_last());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文