繁体   English   中英

PHP BASE64到图像的转换

[英]PHP BASE64 to Image convert

base64是jpeg。 以下是我给定的PHP:

$img['img'] = 'img1.png';
$filedata = explode(',', $this->input->post('lostimage1'));
write_file('./uploads/'.$data['pet_hidenum'].'/'.$img['img'], $filedata[1]);

如何确定给定的b​​ase64是jpeg还是png? 我的代码工作正常,但我只想知道base64字符串是jpeg还是png

$imagedata = base64_decode("****");
$file = finfo_open();
$mime_type = finfo_buffer($file, $imagedata, FINFO_MIME_TYPE);

请参考此链接。

将base64代码传递到PHP的mime_content_type函数中。

<?php
    // Will retrun as image/jpg or image/png depending on the type
    $fileType = mime_content_type("base64codegoeshere");
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM