PHP converts the Base64 into pictures and saves the star small stack

Source: Internet
Author: User

  Publicfunction setbasetoimg (Request $request) {$base 64_image_content= $requestGet('imgBase64','imgBase64'); //match the format of the picture$preg = Preg_match ('/^ (data:\s*image\/(\w+); base64,)/', $base 64_image_content, $result); if($preg) {$type= $result [2]; $new _file= Public_path ('/html5/blessing/baseimg/'); if(!file_exists ($new _file)) {                //Check if there is a folder, if not created, and give the highest permissionsmkdir ($new _file,0700); } $new _file= $new _file.time (). Uniqid ().". {$type}"; if(File_put_contents ($new _file, Base64_decode (Str_replace ($result [1],"', $base 64_image_content)))) {                 return$new _file; }Else{                 return false; }        }    }

Here I use the Laravel framework to bring the method, the following is the original method, all available

   Publicfunction setbasetoimg () {$base 64_image_content= $_post['imgBase64']; //match the format of the picture$preg = Preg_match ('/^ (data:\s*image\/(\w+); base64,)/', $base 64_image_content, $result); if($preg) {$type= $result [2]; $new _file='/html5/blessing/baseimg/'; if(!file_exists ($new _file)) {                //Check if there is a folder, if not created, and give the highest permissionsmkdir ($new _file,0700); } $new _file= $new _file.time (). Uniqid ().". {$type}"; if(File_put_contents ($new _file, Base64_decode (Str_replace ($result [1],"', $base 64_image_content)))) {                 return$new _file; }Else{                 return false; }        }    }

PHP converts the Base64 into pictures and saves the star small stack

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.