PHP $_FILES function

  • 2020-03-31 21:34:57
  • OfStack

Such as:
 
<form enctype="multipart/form-data" action="upload.php" method="post"> 
<input type="hidden" name="MAX_FILE_SIZE" value="1000"> 
<input name="myFile" type="file"> 
<input type="submit" value=" Upload a file "> 
</form> 

Then you can use it directly in upload.php
$_FILES
$_POST
$_GET
Functions such as get the form content.

Today we'll focus on the $_FILES function.
When the client commits, we get an array of $_FILES

The contents of the $_FILES array are as follows:
$_FILES['myFile']['name'] the original name of the client file.
MIME type of $_FILES['myFile']['type'] file, requiring the browser to provide support for this information, such as "image/ GIF ".
$_FILES['myFile']['size'] the size of the uploaded file in bytes.
$_FILES['myFile']['tmp_name'] temporary file name stored on the server after the file is uploaded. It can be specified under php.ini's upload_tmp_dir, but setting it with the putenv() function does not work.
$_FILES['myFile']['error'] and the error code associated with the file upload. ['error'] was added in PHP 4.2.0. Here's what it says :(they became constants after PHP3.0)
UPLOAD_ERR_OK
Values: 0; No errors occurred and the file was uploaded successfully.
UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the limit of the upload_max_filesize option in php.ini.
UPLOAD_ERR_FORM_SIZE
Value: 2; The size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form.
UPLOAD_ERR_PARTIAL
Value: 3; Only part of the file is uploaded.
UPLOAD_ERR_NO_FILE
Value: 4; No files were uploaded.
Value: 5; Upload file size is 0.

After the file has been uploaded, it is stored by default in a temporary directory, at which point you must remove it from the temporary directory or move it somewhere else, or if not, it will be deleted. This means that the files in the temporary directory will be deleted after the script is executed, whether or not the upload is successful. So before you delete, you copy it to another location using PHP's copy() function, and then you're done uploading the file.

Related articles: