/** * 将base64图片数据保存成图片 * @param $image base64字符串 * @param string $path 保存路径 * @return bool|string 保存成功返回路径否则返回flase */ function base64ToImgFile($image,$path='/apply/upload/'){ $imageName = "b64_".date("His",time())."_".rand(1111,9999).'.png'; if (strstr($image,",")){ $image = explode(',',$image); $image = $image[1]; } $path = $path.date("Ym",time()); if (!is_dir($_SERVER['DOCUMENT_ROOT'].$path)){ //判断目录是否存在 不存在就创建 mkdir($path,0777,true); } $imageSrc= $_SERVER['DOCUMENT_ROOT'].$path."/". $imageName; //图片名字 $r = file_put_contents($imageSrc, base64_decode($image));//返回的是字节数 if (!$r) { return false; }else{ //return true; return $path."/". $imageName; } }
PHP 前台的base64图片数据在后台保存成图片文件
猜你喜欢
转载自www.cnblogs.com/kerryw/p/9481753.html
今日推荐
周排行