File Upload and java File Upload
There are two steps to upload a file:
1,Client user upload;
A) a form field is required to inject the file to be uploaded,
<input type="file" name="file" />
B) Select the file to be uploaded.
C) the user clicks to send the file to the server
2,Server receiving
Form uses the POST submission method.
* Note: GET and POST cannot submit binary files, but you can add an attribute for POST submission.
<form action="file.php" method="POST" enctype="multipart/form-data">
Html section:
Html part: <! DOCTYPE html>
Php Section
Var_dump ($ _ FILES) is an array.
array 'file' => array 'name' => string '4.jpg' (length=5) 'type' => string 'image/jpeg' (length=10) 'tmp_name' => string 'F:\wamp\tmp\php904D.tmp' (length=23) 'error' => int 0 'size' => int 273665
Data verification is required.
A) locate the error point based on the two-dimensional array;
Switch ($ _ FILES ['file'] ['error']) {case '0': echo "uploaded successfully"; break; case '1': case '2 ': header ('refresh: 3366url%file.html '); echo "file size exceeds server limit"; break; case '3': header ('refresh: 3366url%file.html '); echo "only part of the file is successfully uploaded"; break; case '4': header ('refresh: 3366url1_file.html '); echo "unselected file, please reselect the file and submit "; break; default: echo "File Upload Failed ";}
B) after the file is uploaded successfully, it is stored in the specified temporary directory and needs to be changed to the expected file,
Php has a function to complete,Move_uploaded_file ()
Eg:
move_uploaded_file($_FILES['file']['tmp_name'], './cy1/' . $_FILES['file']['name']);
Note: tmp_name: the temporary directory on which the file is uploaded to the server,
'Name' indicates the name of the local file on the client.