Php getting started learning knowledge point 3 PHP Upload

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

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.