简体   繁体   中英

How can I convert BASE64 to Image in Codeigniter?

Codeigniter Code:

$filedata = explode(',', $this->input->post('lostimage1'));
$pos  = strpos($this->input->post('lostimage1'), ';');
$type = explode(':', substr($this->input->post('lostimage1'), 0, $pos))[1];
$type = '.'.$type;
$type = str_replace('image/', '', $type);
$img1 = $img['img'].''.$type;
write_file('./uploads/'.$data['pet_hidenum'].'/'.$img1, $filedata[1]);

My code is working fine. when I am downloading the image from the server and opening it image in paint or chrome then it displaying error invalid bitmap How can I resolve this error?

Try something along these lines:

$image = imagecreatefromjpeg($filename);
echo '<img src="data:image/jpeg;base64,'.base64_encode(imagejpeg($image)).'" />';

See this post for more information on this https://delboy1978uk.wordpress.com/2014/12/01/outputting-images-as-base64-encoded-strings/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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