php将base64格式图片保存在指定目录 php实现将base64格式图片保存在指定目录的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

php将base64格式图片保存在指定目录 php实现将base64格式图片保存在指定目录的方法

魁兄   2021-03-22 我要评论
想了解php实现将base64格式图片保存在指定目录的方法的相关内容吗,魁兄在本文为您仔细讲解php将base64格式图片保存在指定目录的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php,base64格式,图片,保存,指定目录,下面大家一起来学习吧。

本文实例讲述了php实现将base64格式图片保存在指定目录的方法。分享给大家供大家参考,具体如下:

<?php
header('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.softyun.net/transcoding/img2base64

在线Email邮箱图标制作工具:
http://tools.softyun.net/email/emaillogo

在线PS图像处理工具:
http://tools.softyun.net/aideddesign/webps

在线图片格式转换(jpg/bmp/gif/png)工具:
http://tools.softyun.net/aideddesign/picext

ICO图标在线生成工具:
http://tools.softyun.net/aideddesign/ico_img

希望本文所述对大家PHP程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们