On the server, Judge:
1) receive data post 2)enctype= "Multipart/form-data" Property
3) Move_uploaded_file: Move the file to the specified location
PHP.ini Temporary file configuration File_uploads = on upload_tmp_dir = "
Vanishing time for temporary files: temporary files disappear immediately after the. php file is accepted.
If not, the contents of the temporary file can be observed when the PHP file is not finished;
The client determines the size of the upload file: JS is not allowed to manipulate local files
Ajax is unable to determine the size of the uploaded file at the client
1.php File Upload process:
To do a file upload form:
<form action= "up.php" method= "POST" >
User name: <input type= "text" name= "username"/><br/>
Avatar: <input type= "file" name= "Pic"/><br/>
<input type= "Submit" value= "Submission"/>
</form>
1) After submission, the file is automatically sent to the server, forming a temporary file,
2) on the server, just need to move the temporary files to their desired location, you can complete the upload file
After PHP forms a temporary file, it also forms a $_files super global array
The array holds the temporary address, temporary name, size, and other information of the file.
Note: File upload must be submitted with post
In the up.php:
<?php
Print_r ($_files);
?>
An empty array is printed on the browser at this time
WORKAROUND: Declare the ENCTYPE option
That is: Declare in form: Enctype= "Multipart/form-data" property
Notifies the other server of the binary information form data that contains the file
It will appear:
{
Name: Upload file name
Type: File type
Tem_name: Temporary file name
Error: Fault code
Size: The file size is expressed in bytes;
}
3) How to move the uploaded temporary files
Using the Move_uploaded_file () function <?php
Print_r ($_files);
if (Move_uploaded_file ($_files[' pic '] [' tmp_name '], './file/'. $_files[' pic ' [' name '])) {
echo "Success";
}else{
echo "fail";
}
PHP File Upload