PHP Introductory Learning Knowledge Point three PHP upload _php basics

Source: Internet
Author: User
Tags mkdir
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.