base64圖片編碼轉換,寫了個方法。兩個參數,一個是ba
/** * base64轉碼圖片 * @param $base64 * @param string $path * @return bool|string */ function get_base64_img($base64, $path = 'data/upload/sign/') { if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64, $result)) { $type = $result[2]; $new_file = $path . time() . ".{$type}"; if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64)))) { return $new_file; } else { return false; } } }