您的位置:首页 > 编程语言 > PHP开发

PHP base64 图片(备忘)

2015-12-09 20:54 676 查看
$image_file = './164175_100.jpg';
$image_info = getimagesize($image_file);
$base64_image_content = "data:{$image_info['mime']};base64," . chunk_split(base64_encode(file_get_contents($image_file)));

//然后保存

$upfile = $_POST['upfile'];//编码后的图片
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $upfile, $result)){
$type = $result[2];
$filename = TIME.'.'.$type;
$new_file = ROOT.'temp';//保存的路径
if (!file_put_contents($new_file, base64_decode(str_replace($result[1], '', $upfile)))){
return array('Error'=>1,'Msg'=>'上传图片失败。');
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: