PHP uploading files from a form - how to resolve issues (legacy version only)

PHP uploading files from a form - how to resolve issues (legacy version only)

IMPORTANT: this is for legacy version of API and on-prem version with file uploading from forms.

If you experience issues uploading file from HTML form then please try to resolve using the following step:

  1. Try to use urlencode() for filenames that may contain spaces. Example: urlencode($_FILES["files"]["name"][$i])

  2. Check HTML form to make sure it uses POST method but not GET

  3. Search for file_uploads constant in php.ini. On some configurations, it may have been set to the zero so no uploads are allowed at all.

  4. Check upload_max_filesize in php.ini. PHP may return 500 error if input file is larger than this option, i.e. if uploaded file is larger than max allowed file size.

  5. Check post_max_size constant in php.ini. PHP uses this constant to set limits for the the total size of that comes from submitted form (including non-file fields too). If total submitted data size is larger than this constant, you will get 500 error.

  6. Check upload_tmp_dir in php.ini which defines temp folder. This folder is used to temporary store data. Sometime this folder is not writable. To resolve the issue, make sure that temp folder is writable from PHP.

  7. Finally, enable PHP errors using the following code snippet in your PHP script:

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

Reference: Fix: PHP upload form not working. by Double You Media, Wexford, Ireland. Retrieved on April 22, 2022.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.