File upload and java file upload. File upload: java file upload is divided into two steps: 1. the client user uploads the file; a) a form field is required to inject the file to be uploaded, inputtypefilename file uploads, and java file uploads
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,
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.
Html section:
Html section:
File Upload
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.
Upload the Upload file is divided into two steps: 1. the client user uploads the file; a) a form field is required to inject the file to be uploaded. input type = "file" name = "...