簡體   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