How to make a link to a jpg picture download it?

Hello,
I'm getting a lot of new problems today, so here is my next question, how do i forca browser to save a jpg picture from a link instead of automatically opening it in the browser itself?

The best I could find is this link: http://codingforums.com/archive/index.php?t-34531.html, but It doesn't work. Any good suggestions how to do it?
GuanoFunAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
<a href="saveImage.php?url=image1.jpg">Save image</a>

and in php:


<?php
$url = addslashes($_GET["url"]);
header('Content-type: content-type:octet-stream');
header('Content-Disposition: attachment; filename="'.$url.'"');
readfile('../images/'.$url);
?>

Open in new window

0
 
Maverick_CoolCommented:
i had already answered a similar type in experts. first thing tell is this link a direct link  i mean in html u have the url path or not.
0
 
Maverick_CoolCommented:
please refer to my answere and this question in below URL of EE:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23027377.html
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
GuanoFunAuthor Commented:
Yes, I have multiple logotips stored in JPG, GIF and other formats wich link directly to them. They are accually op the same server just in a /image/ directoy.

But as normaly browser acts when you click an image link - it opens in browser first. I want a person not needing to right-click and choose save target as, but with normal left-click to have act as it would have chosen save-targe-as already.

Basically, the useronly has to choose where to save the file if he wants to. I dont want to automatically download anything for him in any way, I just want to make things easier for the user ;)
0
 
Maverick_CoolCommented:
the above url has all the answere's
0
 
GuanoFunAuthor Commented:
I read that, thanx, but i guess that is asp programming language which im totally not familiar with ... can you maybe axplain me in more detail how i can get that on my server and what to do with it?

I guess i know something just in php, css and javascript :(
0
 
Maverick_CoolCommented:
i am not good at php... sorry
0
 
GuanoFunAuthor Commented:
hmm... maybe you can explain what do with the asp script then?

Raised points to 250, since I see it won't be as easy as I though
0
 
Maverick_CoolCommented:
-------This   creates a file object and gets all its content as binary input
 Set oStream = Server.CreateObject("ADODB.Stream")
                oStream.Open
                   
                oStream.Type = 1
                oStream.LoadFromFile(path)
 -----------------------------------------------------------
                Response.Clear()

------------Setting the reponse buffer so what the whole is downloaded properly------------
                Response.Buffer = true
               
 -----telling the browser/response that content could be anything , the browser should interpet depending on file extension.In your case u can set Jepg see belloe commented code:
//response.ContentType ="image/jpeg"

                Response.ContentType = "whatever"
---------------------
adding the header for download telling rhe browser the  file should considered as attachment not as inline hence it show a save dialog, also i specify the the name as which it should be stored
                Response.AddHeader "content-disposition","attachment; filename=fname.ext"
--------------------------------------------------------------------------
                end select

---------------             reading file object data to response writer which will send the data to browser  
                Response.BinaryWrite oStream.Read
 
-----------clearing all objects/file objects used.....
                oStream.Close : Set oStream = Nothing
0
 
GuanoFunAuthor Commented:
WoW
thanks a lot, the best solution es really the easiest. works just perfect!

/cheer
0
All Courses

From novice to tech pro — start learning today.