Dear Folks, I have simple HTML page and there are one button called "Download". Once user click on that button then user can download the .jpg file. I do not want to open in new window or same window. I just want to know code for that. Please let me. Thanks,
I am not sure that this is possible because usually your browser detects that it is a image and opens it up in the browser. What you could do is put the .jpg file in a zip file and provide a link to the zip file. So when someone clicks on the link they download the zip file and they can easily extract the image from there.
Dear BackSlashDesigns, Thanks for your feedback but, I will not need .zip file to download. Actually in my page have 1000 photos and i want to download them using click on each button for each images. Thanks
I done a quick Google search and most of them say you have to use JavaScript. Look at this website: http://stackoverflow.com/questions/10473932/browser-html-force-download-of-image-from-src-dataimage-jpegbase64
Quick and dirty <a href="./image/test.png" download="Image"><button>Download!</button></a> HTML: Note: the download attribute is not supported by all browsers. Here is a list the ones that support it http://caniuse.com/#feat=download Code (markup):
If you can use php the this is the code $file = '[B]Your file path[/B]'; $known_mime_types=array( "gif" => "image/gif", "png" => "image/png", "jpeg"=> "image/jpg", "jpg" => "image/jpg", );//file type allow to download if (file_exists($file) && array_key_exists($file_extension, $known_mime_types))//check for [B]file exists[/B] & check for [B]file type[/B] { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; } PHP: