Search code examples
phpapachefile-uploaduploadify

PHP & Apache error - where it is shown?


I'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 !


Solution

  • 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.