PHP upload images and secure handling

Source: Internet
Author: User

Upload image

 Public functionimages () {$data=$_files[' File ']; Switch($data[' Type '])            {                 Case' Image/jpeg ':$ext= ' jpg '; Break;  Case' Image/gif ':$ext= ' gif '; Break;  Case' Image/png ':$ext= ' png '; Break; default:$ext= "; Break; }            if($ext){                $file _name=uniqid().‘.‘.$ext;//the new file name                $tmp _name=$data[' Tmp_name '];//temporary file name on server                $file _size=$data[' Size '];//File Size                if($file _size> 204800){                    $result=Array(' stat ' = '-2 ', ' str ' = ' picture ' is greater than 200K '); EchoJson_encode ($result); Exit; }Else{                    $file _path= ' upload/'.$file _name; $img _path= "http://aaaaaaaaa/upload/".$file _name;//the table alone                     if(Move_uploaded_file($tmp _name,$file _path) ==true ){                         $result=Array(' stat ' = ' 1 ', ' str ' = ' + ' Add picture success ', ' img ' = ' + ')$img _path, ' pic ' =$file _name); }Else{                         $result=Array(' stat ' = '-2 ', ' str ' = ' + ' Add picture failed '); }                                                    EchoJson_encode ($result); Exit; }             }Else{                  $result=Array(' stat ' = '-2 ', ' str ' = ' picture ' is not formatted '); EchoJson_encode ($result); Exit; }        }

PHP upload images and secure handling

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.