1

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your help. Could I use a file_put_contents with the result of base64_decode?
@Camoy sure, it's a normal file after the decoding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.