Upload image OnClick

How do you really upload a picture when you click on it? Is there any javascript code for this? This is how I display the image with pure HTML.

<a href="#"><img src="myPic.png" border="0"></a>
+3
source share
4 answers

By assuming “download”, you mean “The reason the user’s browser calls up the“ save or open dialog ”is that you cannot.

You can link to another URL offering the same file, but with the Content-Disposition header set in the application . The specifics of how you could provide such a resource at this URL will depend on the server-side options you offer.

+2

" ..."

script, "Content-type" "Content-disposition". PHP - :

header('Content-Type: image/png'); // or 'image/jpg' or 'image/gif'
header('Content-Disposition: attachment; filename="filename.png"');
readfile('original.png');

UPDATE: , PHP script, , :

  • URL (sig.php?...) readfile. , .
  • script , readfile.
  • script, , mode=download, , , , .
+2

- -. , script , .zip . /, zip voila...

, - , ...

+1

Do you want to open the image in a new window / tab? Or do you want to download it to the user's computer? If you want the user to save the image, you need to set the content type of the resulting file:

<?php
$file = $_GET['file'];

header("Content-Type: application/octet-stream; ");
header("Content-Transfer-Encoding: binary"); 
header('Content-Disposition: attachment; filename="'.basename($file).'"');
readfile($file);
?>

Be sure to check the login so that users cannot download the source files.

-2
source

Source: https://habr.com/ru/post/1714299/


All Articles