PHP upload is also a common function of php. it mainly focuses on the client and server applications. it is much simpler than asp. I. HTML code for uploading forms
The code is as follows:
Note: 1. action is a new Upload
2. the enctype attribute must be written as "multipart/form-data"
II. PHP code
The code is as follows:
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"]."
"; // File name
Echo $ phpupfile ["type"]."
"; // File type
Echo $ phpupfile ["tmp_name"]."
"; // The file name contains the path
Echo $ phpupfile ["name"]."
"; // Upload 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"]."
";
// 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"]).'
'; // 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"
";
Echo 'This File is exists: '. file_exists ($ phpupfile ["name"]).'
';
}
?>
Note: 1. $ _ FILES ["Imgs"] the Imgs is the control name defined in your HTML code.