I have a base64 encoded png, how do I write the image to a file in PHP?
问题 What's the proper way in PHP to create an image file (PNG), when I have the base64 encoding? I've been playing around with: file_put_contents('/tmp/'. $_REQUEST['id'].'.png', $_REQUEST['data']); do I need to decode? should I be using the gd library? 回答1: My best guess is that you simply need to call base64_decode() on $_REQUEST['data'] before writing it to the file. That should be plenty enough :). 回答2: You need to use base64_decode(). AND. Sometimes it is not sufficient. Here is all code