We have talked a lot about File Upload. This is just the most basic simple file upload function, at the same time, this tutorial also introduces the upload principle, usage of various functions, file parameter descriptions, and php. ihi sets the size of the uploaded file. We have talked a lot about File Upload. This is just the most basic simple file upload function, at the same time, this tutorial also introduces the upload principle, usage of various functions, file parameter descriptions, and php. ihi sets the size of the uploaded file.
Script ec (2); script
1. If you upload a small file (2 mb), you do not need to modify the configuration in php tutorial. ini. If you upload a large file, you must modify the configuration.
2. Modify the following content in php. ini:
Post_max_size indicates the maximum value that php can receive through form post.
Upload_max_filesize indicates the maximum value allowed to upload files.
3. Upload form settings
Explanation: 1. The entype attribute must be set to multipart/form-data during upload.
2 It is best to add the hidden domain name value to the form as max_file_size. This hidden domain does not actually limit the size of the uploaded file, but is used to prevent users from mistakenly uploading large files and getting stuck in endless waiting. The actual size limit is the two modifications in php. ini.
4 pre-defined variables $ _ files
First, it is a two-dimensional array,
$ _ Files ['upfile'] ['name'] file name to be uploaded
$ _ Files ['upfile'] ['SIZE'] size of the uploaded file
$ _ Files ['upfile'] ['tmp _ name'] When uploading a file, the file is first saved as a temporary file, and changed to a temporary file name.
$ _ Files ['upfile'] ['type'] File Upload type
$ _ Files ['upfile'] ['error'] error code
Note: $ _ files ['upfile'] ['name'] The upfile here is consistent with the formCorresponding to the name of, do not make a mistake
5. Specific implementation
$ Filename = $ _ files ['upfile'] ['name'];
$ Tmp = $ _ files ['upfile'] ['tmp _ name'];
$ Error = $ _ files ['upfile'] ['error'];
$ Path = "./images /";
If ($ error = 0 ){
If (is_uploaded_file ($ tmp )){
If (move_uploaded_file ($ tmp, $ path. $ filename )){
Echo "Upload successful! ";
} Else {
Echo "script" alert ('file illegal '); history. go (-1); script ";
}
} Else {
Echo "script alert ('invalid operation! '); History. go (-1); script ";
}
} Else {
Echo "script" alert ('upload error, error type: ". $ error." '); history. go (-1); script ";
}
?>