$ _FILES array in PHP is empty

I am trying to get a file downloaded through a PHP script, but is my $ _FILES array always empty? My $ _POST data entry for an HTML file input element has a file name ... No file is created on my local system.

I checked the write access to the temp folder and installed it. I checked phpinfo () to make sure that file downloads are enabled and that they are.

What could prevent this? Can mod_rewrite call anything?

Thanks!

+2
source share
3 answers

When you have the correct enctype ( <form method="post" enctype="multipart/form-data"> ), then check the errno variable in $ _FILES, there are various possible causes for the failure. Usually exceeded MAX_FILE_SIZE.

http://php.net/manual/en/features.file-upload.errors.php

Starting with PHP 4.2.0, PHP returns the corresponding error code along with an array of files. The error code can be found in the file error segment of the array created during the file upload via PHP. In other words, the error can be found in $ _FILES ['UserFile'] ['error'].

UPLOAD_ERR_OK Value: 0; There is no error, the file was uploaded successfully.

UPLOAD_ERR_INI_SIZE Value: 1; the downloaded file exceeds upload_max_filesize in php.ini.

UPLOAD_ERR_FORM_SIZE Value: 2; the downloaded file exceeds MAX_FILE_SIZE, which was specified in the HTML form.

and etc.

+14
source

Do you define enctype in your form?

 <form method="post" enctype="multipart/form-data"> 

The file will not be downloaded if you did not install it.

+12
source

Does the form match the correct enctype?

 enctype="multipart/form-data" 
+3
source

Source: https://habr.com/ru/post/1397438/


All Articles