开发者

PHP & Apache error - where it is shown?

I'开发者_StackOverflow中文版m running PHP with Apache locally on my PC on Windows.

The script uploads files to the server.

When the file size is bigger than upload_max_filesize that is defined in php.ini or the max_execution_time is exceeded, the file is not uploaded to the server and I don't see any message error.

My question is where I can see what was the error message that stopped the file from being uploaded ?

Is that possible to display an appropriate message to the user ?

I would appreciate a code example. Thanks !


See this page: Error Messages Explained for info. In short, you can get file upload error messages from $_FILES['userfile']['error'] where 'userfile' is the name of the form element.

Or just print_r($_FILES); to see all the details of the current file upload.

An example of displaying human-readable error messages to the user might be:

switch($_FILES['userfile']['error'])
{
   case UPLOAD_ERR_INI_SIZE:
      echo 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
   break;
   case UPLOAD_ERR_CANT_WRITE:
      echo 'Failed to write file to disk.';
   break;
   // etc ...
}

max_execution_time is not specifically a file upload error. As troelskn corrected me (see his reply for more info), it's a fatal error and normally can't be caught in PHP, although I did find this other thread which references this post which presents a possible method of catching fatal errors.

Also see the documentation for set_time_limit.


If you're looking to capture the error yourself, look into the set_error_handler function.


You could change your php.ini server setting, or change that per application.

Server side setting: (modify your php.ini file and modify error_reporting to)

error_reporting = E_ALL & E_NOTICE & E_STRICT

For runtime setting: add the following at the very top of your application:

error_reporting(E_ALL & E_NOTICE & E_STRICT);


If a file exceeds upload_max_filesize, you won't really get an error raised in PHP. The $_FILES array will just include this information.

max_execution_time raises a fatal error, so you can't catch it and display something nice to the user. It won't usually happen during file upload, as it is the tame taken by the php script, and that script won't start executing till the file has been completely transferred.

You can see errors in Apache's general error-log.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜