2017-04-19 56 views
0

base64是jpeg。下面是我给定的PHP:PHP BASE64 to Image转换

$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

回答

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

请参阅本link.

0

传递的base64编码为PHP的mime_content_type功能。

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

不能在CodeIgniter中工作。 –

+0

请帮我一下如何在CodeIgniter中运行mime_content_type函数 –