File Upload, Java file upload
File upload is divided into two steps
1 , the client user uploads;
A) A form field is required to inject the file to be uploaded,
<type= "file" name= "file"/>
b) The user chooses the file to be uploaded
c) Click on the user to send the file to the server
2 , the server receives
The form form uses the Post submission method.
* Note: Get,post cannot submit binary files, but post submission adds a property to complete.
<action= "file.php" method= "POST" Enctype= "Multipart/form-data">
HTML section:
HTML section:
DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>File Upload
title>
head><body> <form action= "file.php" method= "POST" enctype = "Multipart/form-data" > < input type = "File" name = "File" /> < input type = "Submit" value = "Submit" />
form> body>
PHP section
Var_dump ($_files) was found to be an array
array ' File ' = = array string ' 4.jpg ' (length=5 )string ' Image/jpeg ' ( length=10) string ' F:\wamp\tmp\php904D.tmp ' (length=23) ' ERROR ' = int 0 ' size ' = = int 273665
Data validation is performed at this time
A) Find the error point based on a two-dimensional array;
Switch ($_files[' file '] [' ERROR ']) {case ' 0 ': echo "upload succeeded"; Break ; Case ' 1 ': Case ' 2 ': header(' refresh:3;url=file.html '); Echo "File size exceeds server limit"; Break ; Case ' 3 ': header(' refresh:3;url=file.html '); Echo "The file only partially uploaded successfully" ; Break ; Case ' 4 ': header(' refresh:3;url=file.html '); Echo "No files selected, please re-select the file and submit"; Break ; default: echo "File upload Failed";}
b) After the file upload is successful, it is placed in the specified temp directory, which needs to be changed to the desired file.
PHP has a function to complete,move_uploaded_file ()
eg
Move_uploaded_file ($_files$_files[' file '] [' name ']);
Note: tmp_name, files are uploaded to the server's temp directory,
' Name ', the file name of the file locally on the client.
http://www.bkjia.com/PHPjc/1128377.html www.bkjia.com true http://www.bkjia.com/PHPjc/1128377.html techarticle file Upload, java file Upload file upload is divided into two steps 1, the client user uploads; a) a form field is required to inject the file to be uploaded, input type = "File" name = " ...