tags:

views:

401

answers:

2

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?

+5  A: 

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 :).

naixn
sigh, that was easy enough, should have done that before asking the question! thanks.
mmattax
+1  A: 

I would think you'd want to decode with base64_decode() unless you are only using it like they are here HERE.

The thing I am sure of is that you will want to sanitize $_REQUEST['id'] before using it.

Chris Kloberdanz
defiantly will sanitize, just trying to be simplistic...
mmattax