PHP Image upload function implementation

Source: Internet
Author: User

Upload image function:


Get current folder location, upload to current folder

In order to upload after the file name repeatedly caused the overwrite, after uploading the change name: Current time + original file name

Only allow file uploads in GIF, JPEG, BMG, JPG format

<form name= "Frm1"  enctype= "Multipart/form-data"  action= ""  method= "POST" >     <input name= "filename"  type= "file"  style= "border:solid 1px  #6ac1e2;  width: 200px; border-radius: 5px "/>    <input name=" submit " type=" Submit " value=" submitted " style=" background-color:  #e28c8e;border-radius: 5px;  font-size: 14px; " /></form><?phpif (Isset ($_post[' submit '))  {     $dir  = dirname (_ _file__);     $dir  = str_replace ("//",  "/",  $dir)  .  "/";     date_default_timezone_set ("PRC");     $date  = date (  "Ymdhis");     $filename  =  $date. $_files[' filename ' [' Name '];      $uploadfile  =  $dir  .  $filename;     $tp  = array ("ImagE/gif "," Image/jpeg "," IMAGE/BMG "," image/jpg "),     if (!in_array ($_files[" filename "[" type "], $TP)  {        echo  ' <script>alert ("Allow uploading of picture formats: Jpg/jpeg /gif/bmp ") </script> ';    }else{         $r _sc  = move_uploaded_file ($_files[' filename '] ["tmp_name"], $uploadfile);         echo  '  ';    }}?>





This article is from the "Shei" blog, make sure to keep this source http://kurol.blog.51cto.com/11433546/1927823

PHP Image upload function implementation

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.