This article is mainly to share with you the PHP conversion Base64 image for the local image and save the method example, I hope to help everyone.
/** * [Convert Base64 picture to local image and save] * @e-mial wuliqiang_aa@163.com * @TIME 2017-04-07 * @WEB http://blog.iinu.com.cn * @p Aram [Base64] $base 64_image_content [Base64 to save] * @param [contents] $path [path to save] */function base64_image_content ( $base 64_image_content, $path) { //matches the format of the picture if (Preg_match ('/^ (data:\s*image\/(\w+); base64,)/', $base 64_ Image_content, $result)) { $type = $result [2]; $new _file = $path. " /". Date (' Ymd ', Time ())." /"; if (!file_exists ($new _file)) { //check if there is a folder, if it is not created, and give the highest permission mkdir ($new _file, 0700); } $new _file = $new _file.time (). ". {$type} "; if (file_put_contents ($new _file, Base64_decode (Str_replace ($result [1], ", $base 64_image_content))) { return ' /'. $new _file; } else{ return false; } } else{ return false; }}