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:
Try to use
urlencode()
for filenames that may contain spaces. Example:urlencode($_FILES["files"]["name"][$i])
Check HTML form to make sure it uses
POST
method but notGET
Search for
file_uploads
constant inphp.ini
. On some configurations, it may have been set to the zero so no uploads are allowed at all.Check
upload_max_filesize
inphp.ini
. PHP may return500
error if input file is larger than this option, i.e. if uploaded file is larger than max allowed file size.Check
post_max_size
constant inphp.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 get500
error.Check
upload_tmp_dir
inphp.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.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.