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