Forum Moderators: coopster

Message Too Old, No Replies

link to make a page download, not load in browser

         

sasori

6:41 pm on Jul 21, 2009 (gmt 0)

10+ Year Member



Hello, is there a way to make a link so that it forces it to bring up the browser's download popup, or simply downloads it to a predefined location, instead of loading in the browser?

I used to know how to 'force download' media files' in perl, but that was ages ago.

Thanks!

andrewsmd

7:15 pm on Jul 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



create a file called download.php and put this code in it
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=theNameYouWant.ext");
readfile("theSourceFileHere.ext");
Then just link to download.php
<a href="download.php">Download</a>

sasori

10:42 pm on Jul 21, 2009 (gmt 0)

10+ Year Member



I was looking into 'header', what I'm stuck on is that each file is dynamically generated from a table.
I tried setting up a post to download.php?file=http://thecontactlistonline.com/contactdetailview.php?cid=663&skey1=&skey2=&skey3=&skey4=&skey5=AL&skey6=&cpage=1&totrecs=18

and the browser displayed:
Header("Content-type: application/octet-stream"); Header("Content-Disposition: attachment; filename=http://thecontactlistonline.com/contactdetailview.php?cid=663"); readfile("http://thecontactlistonline.com/contactdetailview.php?cid=663");

can you tell what I'm doing wrong

Thanks!

andrewsmd

1:33 pm on Jul 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Aren't these files located on the same server as your download.php file? You are already displaying a ? once in the url so when you put in [someplace.com?cid=c663&...] it is screwing up. You would need to replace the ? with something that you know will never appear in the url, and then change it back. However, I would recommend just using your file paths, if they are on the same server. Also, I don't know how this will handle a url anyways. If it's a completely different site, then you may want to read it with curl and save it locally, then make it available for download. Let me know.

sasori

5:01 pm on Jul 24, 2009 (gmt 0)

10+ Year Member



actually, the links are generated on my server. However its the destination page, which is on a different site, that I'm trying to force download. As it is now, I check out the referral with google before clicking on the link on my page. once I click the link, it brings the page up and I select 'save page as'... that is what I'm trying to skip.

sasori

5:02 pm on Jul 24, 2009 (gmt 0)

10+ Year Member



Oh, so then perhaps the curl option is a way, is that simple?

Thanks so much!

lexipixel

6:36 am on Jul 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



search for "eLouai's Download Script".. it will give some good clues -- I am using it to force download of .JPG and .PDF files (rather than display them).

As mentioned, you'll probably need to read the file from the remote server and store to a file on your server to get it to work.