Get meaningful information when fopen() fails (PHP/suPHP)

≯℡__Kan透↙ 提交于 2019-11-29 13:46:16
mpartel

fopen should raise an E_WARNING if it fails. See error_get_last or set_error_handler(*) to catch it. Other than that you can use file_exists and is_readable to check whether the file is missing or there's another (probably permission-related) problem.

(*) I consider it good practice to always set an error handler that turns all PHP errors into exceptions.

Use error_get_last() to catch the (supressed) errors in php:

$f = @fopen("x", "r") or die(print_r(error_get_last(),true));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!