Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hiding download link

    I've been to a few sites where when you download a file the file download dialogue comes up, but instead of saying the name of the file, it says redirect.php or download.php or whatever. But when you select save to disk it then shows you the tru name of the file so that you can browse and save it to disk. I tried header("location: file.exe"), but with that the filename is shown. Any ideas?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I do that with mp3s; a file called download.php in the root directory:
    PHP Code:
    <?

    $saveName 
    stripslashes($HTTP_GET_VARS["name"]);
    $savePath stripslashes($HTTP_GET_VARS["path"]);

    header ("Content-Type: application/octet-stream");
    header ("Content-Disposition: attachment; filename=$saveName");
    header ("Content-Transfer-Encoding: binary");
    readfile($savePath);

    ?>
    And then you call it with URIs like this:
    Code:
    <a title="MP3 download" href="/download.php/?path=music/hifi/song.mp3&name=song.mp3">
    You can improve that by passing the filesize as another parameter; I think there's a header for that as well, something like "File-Size" - that way, the download dialogue will tell you how big it is, and estimate the download time
    Last edited by brothercake; 03-15-2003 at 01:16 AM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works like a charm. Thanks.

    Just a couple things I'd also like to ask. First off is there any way the user can tell where the file really is if I don't use a form, just the header part (doubt it but want to be sure)? Also, if I'm using this with a larger file will it require a lot of work on the servers part to parse the file?
    Last edited by x_goose_x; 03-15-2003 at 04:23 AM.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Filesize:

    PHP Code:
    header("Content-Length: ".filesize($filename)); 
    Pulled out of the post by the user "lists at darkcore dot net" on php.net - header

  • #5
    New Coder
    Join Date
    Jan 2003
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    heya

    I have a similar problem like this one.

    I want to have a download link, but instead of filename (in that script you can download a file that you specify) I want to put a direct link(url) to the other site's filename.

    I think that should be just a minor change in the script, but I'm new in php, so any help from you php masters is appreciate.

    thanx in advance

  • #6
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use a database as the mp3 thing is not safe at all...

    use get id
    then do a query and then use some download code for it to prompt to save the file, they wont see the download location except from www.xxx.xxx

  • #7
    New Coder
    Join Date
    Jan 2003
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I need to know what to change in above code that would work with url not with filename.

    I don't wanna use it for mp3's but for pdf/doc files, so hidding link like www.xxx.xxx is not my problem.
    My problem is how to replace/change that line:

    header ("Content-Disposition: attachment; filename=$saveName");

    with something like this:

    header ("Content-Disposition: attachment; URL =$saveName");

    So once again; I have a download link, after I click it I want to get an option like "Save as". My link is basicly just a link to other site's link where is some pdf.

    Could you please corect the above code for me?

    thanx


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •