PHP Get started learning Knowledge point three PHP upload _php tutorial

Source: Internet
Author: User
First, upload the form HTML code
Copy CodeThe code is as follows:


Note: 1, action is the upload of new
2, Enctype this attribute to write "Multipart/form-data"
Second, PHP code
Copy CodeThe code is 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

http://www.bkjia.com/PHPjc/323831.html www.bkjia.com true http://www.bkjia.com/PHPjc/323831.html techarticle first, the HTML code to upload the form copy code code is as follows: Form action= "upload.php" method= "post" enctype= "Multipart/form-data" name= "upfrm" input Type= "File" Name= "IMGs" id= "IMGs" ...

  • 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.