fopen 的详细错误
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
打开错误报告,或者,在生产环境中(从 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()
.对于 5.2 之前的 php 版本(缺少 error_get_last()),您可以使用
另请参阅:http://de.php.net/reserved.variables.phperrormsg
For php versions prior to 5.2 (lacking error_get_last()) you can use track_errors.
see also: http://de.php.net/reserved.variables.phperrormsg
是的。
PHP 为您提供了详细的错误消息。
您只需将其打开即可。
要在屏幕上显示它,请在脚本顶部添加以下两行:
或者如果您希望将其记录下来,
另请注意,使用 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:
Or if you want it to be logged instead,
Also note that using die() is very bad practice.