PHP file Upload move_uploaded_file () the correct wording of the parameter

Source: Internet
Author: User
Tags php file upload

PHP $_files functions in a detailed
Uploading a file in PHP builds a form that is much more flexible than ASP. Specific look at the code.

Such as:
Copy CodeThe code is as follows:
<form enctype= "Multipart/form-data" action= "upload.php" method= "POST" >
<input type= "hidden" name= "max_file_size" value= ">"
<input name= "MyFile" type= "File" >
<input type= "Submit" value= "Upload file" >
</form>

Then the upload.php can be used directly
$_files
$_post
$_get
function to get the contents of the form.

Today we 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.
The MIME type of the $_files[' myFile ' [' type '] file requires the browser to provide support for that information, such as "Image/gif".
$_files[' myFile ' [' size '] the size of the uploaded file, in bytes.
$_files[' myFile ' [' tmp_name '] files are uploaded after the temporary file name stored on the server, usually the system default. Can be specified in the php.ini upload_tmp_dir, but the putenv () function setting is not working.
$_files[' myFile ' [' Error '] and the file upload related error code. [' ERROR '] was added in version PHP 4.2.0. Here is a description of it: (they become constants after PHP3.0)
Upload_err_ok
Value: 0; No error occurred and the file upload was successful.
Upload_err_ini_size
Value: 1; The uploaded file exceeds the value of the Upload_max_filesize option limit 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; The upload file size is 0.

After the file is uploaded, it is stored in the temp directory by default, and you must remove it from the temporary directory or move it to another location, or delete it if it is not. That is, regardless of whether or not the upload succeeds, the files in the temp directory will be deleted after the script executes. So before you delete it, copy it to another location using PHP's copy () function, and it's time to upload the file.



The function is to move the uploaded file to a new location.
There are two parameters, the first parameter is the temporary file name after you upload, automatically generated by the system. Usually the style is:
$_file["FILE" ["Tmp_name"];
Where file is the name of your foreground document upload form.
The second parameter is a new file name that contains a path. Such as:
"Upload/1.jpg";
In this way, you will move your uploaded files to the subdirectory under the name upload in the current directory, and save the file name as: 1.jpg.

php File Upload move_uploaded_file () the correct wording of the parameter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.