Ec (2); Note: whether the file upload is successful depends on whether your written file directory is available, whether the form and post get the same name, and php tutorial. the file size uploaded in ini is not within the writable range. & Lt; html & gt; & lt; body & gt; & lt; formaction & quot; upload_file.php & quot; method & quot; post & quot; enctype & quot; multipa script ec (2); script
Note: whether the file upload is successful depends on whether your written file directory is available, whether the name obtained from the form and post is the same, and whether the size of the uploaded file in php tutorial. ini is within your writable range.
Php code.
$ Store_dir = 'd: upload; // path of the file stored on the server after being uploaded
$ Uploadfile = "$ store_dir". basename ($ _ files ['sendfile'] ['name']); // Original name of the uploaded file
$ Uploadfile_tmp = $ _ files ['sendfile'] ['name _ tmp ']; // temporary name of the uploaded file
$ Err_msg = $ _ files ['sendfile'] ['error']; // error message generated during File Upload
If ($ err_msg ){
Print "error code: $ err_msg
";
}
If (! Is_writeable ($ store_dir) {// check whether the uploaded file is writable.
Print "$ store_dir directory cannot write n ";
Exit;
}
Else {
Print "$ store_dir directory can be written to n ";
}
If (isset ($ _ files ['sendfile']) {
If (is_uploaded_file ($ uploadfile_tmp) {// check whether the uploaded file exists. if so, perform the next step.
Print "file verification succeeded n ";
}
Else {
Print "An error occurred while checking the file. This vulnerability may cause File Upload attacks! ";
Exit;
}
If (move_uploaded_file ($ uploadfile_tmp, $ uploadfile) {// rename the uploaded legal file and move it to the upload folder on the server
Print "File Uploaded successfully n ";
}
Else {
Print "failed to move the file, which may be under file upload attack! ";
Exit;
}
Print "the file has been uploaded!
";
}
Else {
Print "File Upload Failed!
";
}
?>