Is there a way to make an image a download once you click on it (without right-click save image as)?
I\'m using a small Javascript function to call the do
If you're on an apache server this is really simple.
assets/.htaccess
.AddType application/octet-stream .jpg
. You can add a new line for each file extension that you need. E.g. AddType application/octet-stream .pdf
Browsers recognize jpg URL's
and hand them over just like a .htm, so I don't think you can force it on the user-end (not positive on that, though).
Read this
http://apptools.com/phptools/force-download.php
Try to change this:
header("Content-disposition: attachment; filename= ".$file."");
To:
header("Content-disposition: attachment; filename= ".$file);
If the above doesn't work to you, here a function to force a file to be downloadable:
<?php
function downloadFile($file, $type)
{
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: Content-type: $type");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
readfile($file);
}
downloadFile("sd.jpg", "image/jpg");
?>
See if this helps:
Webkit and Excel file(PHPexcel)
This worked for me
header("Pragma: public");
header('Content-disposition: attachment; filename='.$title);
header("Content-type: ".mime_content_type($sample_file));
header('Content-Transfer-Encoding: binary');
ob_clean();
flush();
readfile($sample_file);
I also added the following to .htaccess
SetEnvIf Request_URI "\.jpg$" requested_jpg=jpg
Header add Content-Disposition "attachment" env=requested_jpg
Not sure if that helps?
This is a button you can click on in internet explorer to download pic
<html>
<head>
<title>Your title</title>
</head>
<body>
<form><input type="button" value="Click Me" onClick="window.location.href='image.jpg'"></form>
</body>
</html>