First, the HTML code to upload the form
Copy Code code 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, the action is uploaded new
2, Enctype this attribute to write "Multipart/form-data"
Second, PHP code
Copy Code code as follows:
<?php
if (Is_uploaded_file ($_files["IMGs"] ["Tmp_name"])) {
$phpupfile =$_files["IMGs"];
Output the array structure of uploaded files;
Print_r ($phpupfile);
Output all kinds of information of uploaded files
echo $phpupfile ["size]." <br> "; Filename
echo $phpupfile [' type ']. <br> "; File type
echo $phpupfile ["Tmp_name"]. " <br> "; File name contains path yesterday
echo $phpupfile ["name"]. " <br> "; File name for upload
/*
* Upload error message
* 0 represents successful upload,
* 1, 2 represents more than the set maximum upload value
* 3 represents only partial uploads
* 4 means no files are uploaded
* 5 represents the upload file size of 0
*/
echo $phpupfile ["Error"]. " <br> ";
Upload function (when the form is submitted, the uploaded file is saved in a temporary folder on the server, and it needs to be moved 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 part is an additional part
*/
To determine if a file exists, 1 represents a presence, and 0 delegates are not found
Echo ' This File is exists: '. file_exists ($phpupfile [' name ']). ' <br> '; Query whether a file or directory exists
Unlink Delete Files
Echo ' deletes file: '. Unlink ($phpupfile [' name ']). ' 1 for deletion success, 0 for deletion failure ';
mkdir Create a folder
if (file_exists (' pic ') ==false) {
mkdir ("pic");
}
if (file_exists (' pic/ts ') ==false) {
mkdir ("Pic/ts");
}
RmDir Delete Folder
if (file_exists (' pic/ts ') ==false) {
RmDir (' pic/ts ');
}
Rename renaming
Rename ("Guitar11-hp-sprite.png", "1.png");
echo "<br>";
Echo ' This File is exists: '. file_exists ($phpupfile [' name ']). ' <br> ';
}
?>
Note: 1, $_files["IMGs"] This IMGs is the name of the control defined in your HTML code