0

I want to save the image as a file on the server, and store the name of the image file in database.. How do I do that using php?

or should I just store the image data in the db, using a post request..?

imagedata = canvas.toDataURL("image/png")

can i simply do a post request using imagedata as a variable, or do i have to encode it before. I'm relatively new to web development..

i also want to retrieve the image data from the db..

simply put, all I have is imagedata how do i go about storing it on a server and retrieving it again later.

syllogismos
  • 600
  • 2
  • 15
  • 39
  • dataurls are just base64-encoded. you can sent that over to the server via ajax or normal a normal POSTed form, base64_decode it there, then stuff it into the db. however, storing files/images in the database usually just causes more trouble than any minor benefits you can gain, so you might be better writing it out to an actual file on the server and simply pointing your db at that new file. – Marc B Dec 10 '12 at 20:04
  • @MarcB how do i write it as an actual file? – syllogismos Dec 10 '12 at 20:08
  • could be as simple as `file_put_contents('somefile.png', base64_decode($_POST['yourimage']))` – Marc B Dec 10 '12 at 20:10
  • @MarcB i found it here, i will give it a try.. http://j-query.blogspot.in/2011/02/save-base64-encoded-canvas-image-to-png.html i think i found what i want.. i will give it a try – syllogismos Dec 10 '12 at 20:11
  • http://stackoverflow.com/questions/4917811/file-put-contents-permission-denied this helps too – syllogismos Dec 11 '12 at 16:08

0 Answers0