Q2Ftb3k
Q2Ftb3k

Reputation: 688

Create Image from Data URL

What I was hoping to do was use the JavaScript "readAsDataURL" method of the "FileReader" object in order to read file input from a drag and drop. Then I wanted to use Ajax with a PHP upload file in order to create a file and upload it to an "uploads" folder on the server.

I was wondering if there was a function in GD or something that would allow me to read in a data URL and output a file in which I could move to that folder.

Upvotes: 1

Views: 2659

Answers (1)

Pekka
Pekka

Reputation: 449395

A data image URL will usually be base64 encoded, and will then contain a JPG, GIF, or PNG image which you can store.

So a simple base64_decode() should do to turn the data into readable form; if you can't know what format the file was in, you may have to write it onto disk to do a getimagesize() on it (unless you can use one of the new "memory" fopen wrappers shown here).

Upvotes: 1

Related Questions