PHP后台接收Base64圖片的時候,如何將該字符串轉成圖片呢?
使用base64_decode 和 fopen和fwrite組合的方法,將圖片成功還原;
//$img為傳入字符串 $img = str_replace('data:image/png;base64,', '', $img); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $imgPath="test.png"; if(@file_exists($imgPath)){ @unlink($imgPath); }@clearstatcache(); $fp=fopen($imgPath,'w'); fwrite($fp,$data); fclose($fp);