本文实例讲述了php实现将base64格式图片保存在指定目录的方法。分享给大家供大家参考,具体如下:
<?phpheader("Content-type:text/html;charset=utf-8");$base64_image_content = $_POST["imgBase64"];//匹配出图片的格式if (preg_match("/^(data:s*image/(w+);base64,)/", $base64_image_content, $result)){$type = $result[2];$new_file = "upload/active/img/".date("Ymd",time())."/";if(!file_exists($new_file)){//检查是否有该文件夹,如果没有就创建,并给予最高权限mkdir($new_file, 0700);}$new_file = $new_file.time().".{$type}";if (file_put_contents($new_file, base64_decode(str_replace($result[1], "", $base64_image_content)))){echo "新文件保存成功:", $new_file;}else{echo "新文件保存失败";}}?>
PS:这里再为大家推荐几款在线图片工具供大家参考使用图片转换为Base64编码在线工具:http://tools.jb51.net/transcoding/img2base64
在线Email邮箱图标制作工具:http://tools.jb51.net/email/emaillogo
在线PS图像处理工具:http://tools.jb51.net/aideddesign/webps
在线图片格式转换(jpg/bmp/gif/png)工具:http://tools.jb51.net/aideddesign/picext
ICO图标在线生成工具:http://tools.jb51.net/aideddesign/ico_img
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP图形与图片操作技巧汇总》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。