First, upload the form HTML code
Copy the Code code as follows:
Note: 1, action is the upload of new
2, Enctype this attribute to write "Multipart/form-data"
Second, PHP code
Copy the Code code as follows:
if (Is_uploaded_file ($_files["IMGs" ["Tmp_name"])) {
$phpupfile =$_files["IMGs"];
The array structure of the output upload file;
Print_r ($phpupfile);
Output various types of information for uploading files
echo $phpupfile ["size"]. "
"; Filename
echo $phpupfile ["type"]. "
"; File type
echo $phpupfile ["Tmp_name"]. "
"; File name contains path yesterday
echo $phpupfile ["name"]. "
"; File name of the upload
/*
* Upload error message
* 0 means successful upload,
* 1, 2 means the maximum upload value is exceeded.
* 3 represents only partial uploads
* 4 means no files are uploaded
* 5 for upload file size 0
*/
echo $phpupfile ["Error"]. "
";
Upload function (when you submit the form, the uploaded file is saved in the Temp folder of the server, and you need to move it to the specified folder in the Web site)
Move_uploaded_file ($phpupfile ["Tmp_name"], $phpupfile ["name"]); Save the uploaded file to the specified folder
/*
* The following sections are additional parts
*/
Determine if the file exists 1 is present, 0 means not found
Echo ' This File is exists: '. file_exists ($phpupfile ["name"]). '
'; Querying whether a file or directory exists
Unlink Deleting files
Echo ' Delete file: '. Unlink ($phpupfile ["name"]). '; 1 for delete succeeded, 0 for delete failed ';
mkdir Creating a Folder
if (file_exists (' pic ') ==false) {
mkdir ("pic");
}
if (file_exists (' pic/ts ') ==false) {
mkdir ("Pic/ts");
}
RmDir Deleting a folder
if (file_exists (' pic/ts ') ==false) {
RmDir (' pic/ts ');
}
Rename renaming
Rename ("Guitar11-hp-sprite.png", "1.png");
echo "
";
Echo ' This File is exists: '. file_exists ($phpupfile ["name"]). '
';
}
?>
Note: 1, $_files["IMGs"] This IMGs is the name of the control you define in your HTML code
The above introduces the learning of the mass line of education practice experience of learning PHP introductory knowledge point three PHP upload, including the learning of the mass Line education practice experience aspects of the content, I hope that the PHP tutorial interested friends have helped.