I. HTML code for uploading forms
Copy codeThe Code is as follows:
<Form action = "UpLoad. php" method = "post" enctype = "multipart/form-data" name = "upFrm">
<Input type = "file" name = "Imgs" id = "Imgs">
<Input type = "submit" name = "subBtn" value = "Upload">
</Form>
Note: 1. action is a new upload
2. The enctype attribute must be written as "multipart/form-data"
Ii. PHP code
Copy codeThe Code is as follows:
<? Php
If (is_uploaded_file ($ _ FILES ["Imgs"] ["tmp_name"]) {
$ Phpupfile = $ _ FILES ["Imgs"];
// Output the Array Structure of the uploaded file;
Print_r ($ phpupfile );
// Output all types of information about the uploaded file
Echo $ phpupfile ["size"]. "<br>"; // file name
Echo $ phpupfile ["type"]. "<br>"; // file type
Echo $ phpupfile ["tmp_name"]. "<br>"; // the file name contains the path
Echo $ phpupfile ["name"]. "<br>"; // uploaded file name
/*
* Upload error message
* 0 indicates that the upload is successful,
* 1 or 2 indicates that the maximum upload value is exceeded.
* 3 indicates that only partial uploads are allowed.
* 4 indicates that no file is uploaded.
* 5 indicates that the size of the uploaded file is 0.
*/
Echo $ phpupfile ["error"]. "<br> ";
// Upload function (after the form is submitted, the uploaded file is saved in the temporary folder on the server. In this case, you need to move it to the specified folder on the website)
Move_uploaded_file ($ phpupfile ["tmp_name"], $ phpupfile ["name"]); // Save the uploaded file to the specified folder
/*
* The following are additional parts.
*/
// Determine whether the object exists. 1 indicates that the object exists, and 0 indicates that the object is not found.
Echo 'this File is exists: '. file_exists ($ phpupfile ["name"]).' <br> '; // query whether a File or directory exists
// Unlink
Echo 'delete file: '. unlink ($ phpupfile ["name"]).'; 1 indicates that deletion is successful, and 0 indicates deletion failed ';
// Create a folder using mkdir
If (file_exists ('pic ') = FALSE ){
Mkdir ("pic ");
}
If (file_exists ('pic/Ts') = FALSE ){
Mkdir ("pic/ts ");
}
// Rmdir delete a folder
If (file_exists ('pic/Ts') = FALSE ){
Rmdir ('pic/Ts ');
}
// Rename
Rename ("guitar11-hp-sprite.png", "1.png ");
Echo "<br> ";
Echo 'this File is exists: '. file_exists ($ phpupfile ["name"]).' <br> ';
}
?>
Note: 1. $ _ FILES ["Imgs"] The Imgs is the control name defined in your HTML code.