PHP File Upload Processing

Source: Internet
Author: User

file_up.php

<? PHP Header ("Content-type:text/html;charset=utf-8");? ><form action= "file_chuli.php" enctype= "Multipart/form-data" method= "POST" ><input type= "file" Name= " File "/><input type=" submit "value=" Upload "/></form>
View Code

file_chuli.php

<?PHPHeader("Content-type:text/html;charset=utf-8");/*$file = $_files["file"];        All information about the uploaded file is stored in the $_files["file"] array;         echo $_files["File" ["Name"];        Take the filename echo $_files["file" ["type"];       Fetch file type echo $_files["file" ["Size"];    Fetch file size echo $_files["file" ["Tmp_name"];    File on the server temporary storage path echo $_files["file" ["Error"]; Upload error messages, no errors display 0*///File Upload  if($_files["File"] ["Error"]){    Echo"Upload Error!" ";} Else{          //1. Restrictions on adding conditions          if($_files["File"] ["type"] = = "Image/jpeg" &&$_files["File"] ["Size"]<2048000)          {                  //2. Working with file names                  $str=Date("Ymdhisms", Time()); //3. Create a storage path                  $url= ".. /test/".$str.$_files["File"] ["Name"]; //4. Turn the path to GB to prevent file name garbled                  $filename=Iconv("Utf-8", "gb2312",$url); if(file_exists($filename))                  {                      Echo"The file already exists"; }                      Else                  {                            //5. Storage                                           Move_uploaded_file($_files["File"] ["Tmp_name"],$filename); Echo"Upload success!" "; }                          }              Else        {            Echo"Upload file type does not meet the requirements"; }        }?>
View Code

PHP File Upload Processing

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.