I want to know if there is any way to make a button that allows to download images that are saved in another server from a URL. That is, like right click - save image as but with a button. I searched for solutions with PHP or JavaScript but haven't found anything yet.
The HTML5 attribute download
does not work in all browsers. Is there an alternative with JavaScript?
Using HTML5 you can use the " download " attribute
Demo: https://jsfiddle.net/Socramg/1o9oec7r/
Using JS (and jQuery )
Demo: https://jsfiddle.net/Socramg/1o9oec7r/1/
What you can do is with PHP first copy the image to the server and then download it, for example:
now to download it is you can use this code
You can do it with JavaScript programmatically like this:
You can also download using PHP in the following way:
This is an example are two files the PHP and HTML
Download.php
and only by means of a line in an html you call it
For me, the download attribute did not work since, being an image, my browser sent the display by default.
In the end I managed it with the following function in javascript.
Thanks to Sapan Bodiwala, as I got the example from his page. https://dev.to/sbodi10/download-images-using-javascript-51a9
Depending on how the other server is configured this may not work, since hotlinking, or whatever this technique is called, is banned on some machines, although it shouldn't be a problem if you can configure it.