Home  >  Article  >  Backend Development  >  Detailed description of $_FILES function in PHP

Detailed description of $_FILES function in PHP

韦小宝
韦小宝Original
2018-05-23 16:57:5712184browse

Uploading is often used in our daily PHP development. The $_FILES system function that we have to mention in uploading and what does it represent? This article will talk about the system in PHP in detail. Function $_FILES.

For example:

<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="上传文件"> 
</form>

Then upload.php can directly use functions such as
$_FILES
$_POST
$_GET
to obtain the form content.
Today we focus on the $_FILES function.
When the client submits, we obtain a $_FILES array
The contents of the $_FILES array are as follows:

$_FILES[&#39;myFile&#39;][&#39;name&#39;] //客户端文件的原名称。 
$_FILES[&#39;myFile&#39;][&#39;type&#39;] //文件的 MIME 类型,需要浏览器提供该信息的支持,例如"image/gif"。 
$_FILES[&#39;myFile&#39;][&#39;size&#39;] //已上传文件的大小,单位为字节。 
$_FILES[&#39;myFile&#39;][&#39;tmp_name&#39;] //文件被上传后在服务端储存的临时文件名,一般是系统默认。可以在php.ini的upload_tmp_dir 指定,但 用 putenv() 函数设置是不起作用的。 
$_FILES[&#39;myFile&#39;][&#39;error&#39;] //和该文件上传相关的错误代码。[&#39;error&#39;] 是在 PHP 4.2.0 版本中增加的。下面是它的说明:(它们在PHP3.0以后成了常量)

UPLOAD_ERR_OK
Value: 0; None An error occurred and the file uploaded successfully.

UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the value limited by 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 was uploaded.

UPLOAD_ERR_NO_FILE
Value: 4; No file was uploaded.
Value: 5; The uploaded file size is 0.
After the file is uploaded, it is stored in the temporary directory by default. At this time, you must delete it from the temporary directory or move it to other places. If If not, it will be deleted. That is to say, regardless of whether the upload is successful or not, the files in the temporary directory will definitely be deleted after the script is executed. Therefore, you need to use PHP's copy() function to copy it to another location before deleting it. At this time, the file upload process is completed.

Related recommendations:

php $_FILES Detailed explanation of $_FILES

How to use $_FILES in PHP and how to use it Notes


The above is the detailed content of Detailed description of $_FILES function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn