Php file upload details

Source: Internet
Author: User
Tags php file upload
First, I would like to declare that this chapter contains a lot of content, which is difficult. you should hold on to yourself. Not to mention the nuances. it is King to think more and practice more. Learning is like hiking. you have to set a small goal for yourself step by step, and then persistently climb up to reach the peak. Please carefully consider the above two statements. 1. my preparations. Editor: sublimetext3. Not to mention the nuances. it is King to think more and practice more.

Learning is like hiking. you have to set a small goal for yourself step by step, and then persistently climb up to reach the peak.

Please carefully consider the above two pieces of advice

1. my preparations.

Editor:Sublime text3 (which editor is used to view your hobbies)

Server construction:Use phpstudy2014 to build a server. the server files are stored in the www file on the D drive of my computer. (When phpstudy is installed, the www file is automatically generated ). Run phpstudy and enter localhost in the address bar of the browser to access files on the server.

File upload process:The browser uploads a file on the client and click Submit. the file is sent to a php file on the server for processing. The php saves the uploaded file to the server.

II. create a form

View my html code

 0) {echo "error:". $ _ FILES ["myfile"] ["error"]."
"; // For example, if the server space is insufficient, an error occurs when only part of the file can be uploaded. } Else {echo "Upload file name:". $ _ FILES ["myfile"] ["name"]."
"; Echo" file type: ". $ _ FILES [" myfile "] [" type "]."
"; Echo" file size: ". ($ _ FILES [" myfile "] [" size "]/1024)." kB
"; Echo" file temporary storage location: ". $ _ FILES [" myfile "] [" tmp_name "]."
";}} Else {echo" illegal file format ";}?>


4. Save uploaded files

After the file is uploaded, it is saved in a temporary location. When the script ends, it will disappear. If you want to save it permanently on the server, we need to save it in another location.

. File_exists ("upload/". FILES ["file"] ["name"]) check whether a file or directory exists .. Moveuploadedfile (_ FILES ["file"] ["tmp_name"], "upload /". $ _ FILES ["myfile"] ["name"]); transfers the uploaded file from a temporary location to the server space.

 0) {echo "error:". $ _ FILES ["myfile"] ["error"]."
";} Else {echo" Upload file name: ". $ _ FILES [" myfile "] [" name "]."
"; Echo" file type: ". $ _ FILES [" myfile "] [" type "]."
"; Echo" file size: ". ($ _ FILES [" myfile "] [" size "]/1024)." kB
"; Echo" file temporary storage location: ". $ _ FILES [" myfile "] [" tmp_name "]."
"; // Determine whether the upload Directory (created by yourself and named by yourself) under the current directory (that is, in the www folder) exists in this file. // if there is no upload directory, you need to create it, the upload directory permission is 777 if (file_exists ("upload /". $ _ FILES ["myfile"] ["name"]) {echo $ _ FILES ["myfile"] ["name"]. "The file already exists. ";} Else {// if the upload directory does not exist, upload the file to the upload directory move_uploaded_file ($ _ FILES [" myfile "] [" tmp_name "], "upload /". $ _ FILES ["file"] ["name"]); // echo "the file is stored in :". "upload /". $ _ FILES ["myfile"] ["name"] ;}} else {echo "illegal file format" ;}?>

The above is a detailed description of PHP file upload. For more information, see PHP Chinese network (www.php1.cn )!

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.