Upload images in PHP background

Source: Internet
Author: User

With the last blog, tinkering with a PHP backstage things, although not understand, but slowly, still Can. Transmission Door

Java is not studious, play php, meet Yourself.

The image compression effect is obvious, actually compressed several times.

<?PHPHeader(' content-type:text/html; charset= "utf-8");$base 64_image_content=$_post["file"];//var_dump ($ $base 64_image_content);if(Preg_match('/^ (data:\s*image\/(\w+); base64,)/i ',$base 64_image_content,$result)){    $type=$result[2]; $new _file= "upload/".Date("Ymd", time())." /"; if(!file_exists($new _file)){        /*Permissions issues, 0777 is best, others may be banned*/        mkdir($new _file, 0777); Echo"created successfully"; }Else{        Echo"create failed"; }    $new _file=$new _file. time().". {$type}"; if(file_put_contents($new _file,Base64_decode(Str_replace($result[1], "",$base 64_image_content)))){        EchoSuccess; }Else{        EchoFailed; }    }Else{    Echo"not match!!";}?>

form submission, Transferring pictures

<?PHPHeader(' content-type:text/html; charset= "utf-8");$upload _dir= ' uploads/';if(Strtolower($_server[' Request_method ']) ! = ' Post ') {exit_status (Array(' code ' =>1, ' msg ' = ' Error submission method '));}if(array_key_exists(' file ',$_files) &&$_files[' file '] [' error '] = = 0 ){        $pic=$_files[' file ']; if(Move_uploaded_file($pic[' Tmp_name '],$upload _dir.$pic[' name ']) {exit_status (Array(' code ' =>0, ' msg ' = ' upload succeeded ', ' url ' = =$upload _dir.$pic[' name '])); }    }Echo $_files[' file '] [' error '];exit_status (Array(' code ' =>1, ' msg ' = ' = ' There have been some errors '));functionExit_status ($str){    EchoJson_encode ($str); Exit;}?>

Upload images in PHP background

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.