1

I have a image with id='canvasaImg' that sits on my webpage. I was wondering if it was possible to save this image to the server with javascript or if it has to be done with php.

user1567505
  • 131
  • 1
  • 6

3 Answers3

0

Short answer - You can't do this with JavaScript alone - you'll have to use some serverside code too.

Long answer - JavaScript is a client side technology. It has no control over the server. What you might be able to do is execute an AJAX call to your server containing the path to the image and then with PHP (or any other server side language) you could use file_get_contents() to copy the image to your server.

Lix
  • 47,311
  • 12
  • 103
  • 131
  • Do you know how I would go about saving the image on my webpage with php? How do you grab that specific image? – user1567505 Nov 11 '12 at 14:40
  • Well.. If the AJAX call brings along the path then you have all you need. You can use `file_put_contents()` to save a file to disk on the server. – Lix Nov 11 '12 at 14:41
0

No, you can't.

Yes, you have to use PHP or another server-side language.

However, there is another way to interpret your question which would give the answer: Yes, you can save an image to the server using JavaScript with Node.js (Note that Node.js is a web server which uses JavaScript)

Willem
  • 1,094
  • 1
  • 12
  • 23