Professional Web Applications Themes

how to hide the url of a file for downl load? - PHP Development

I'd like to let user download a file but I'd like to hide the url of the file. I'd like to write something like that: <a href="download_file.php?id=1123">download file</a> download_file.php get the file and give it to user. BUT... .... how can I write download_file.php? thank you in advance for your help, Andrea....

  1. #1

    Default how to hide the url of a file for downl load?

    I'd like to let user download a file but I'd like to hide the url of the
    file.
    I'd like to write something like that:

    <a href="download_file.php?id=1123">download file</a>

    download_file.php get the file and give it to user.
    BUT...
    .... how can I write download_file.php?
    thank you in advance for your help,
    Andrea.


    _andrea.l Guest

  2. #2

    Default Re: how to hide the url of a file for downl load?

    _andrea.l wrote: 

    something similar to this:

    (by the way: have a look at the header function of PHP)

    download_file.php

    //get the real filename
    $file=realfilename();

    header("Content-type: application/force-download");
    header("Content-Transfer-Encoding: Binary");
    header("Content-length: ".filesize($file));
    header("Content-disposition: attachment;
    filename=\"".basename($file)."\"");
    readfile("$file");

    Regards
    Stefan
    Stefan Guest

  3. #3

    Default Re: how to hide the url of a file for downl load?

    > I'd like to let user download a file but I'd like to hide the url of the 



    <?php
    // download_file.php
    $file_locations = array(
    1 => 'my/location/file1.zip',
    2 => 'my/dislocation/file2.doc',
    1123 => 'some/important/file.dbf'
    );

    Header( 'Location: http://my.server.com/' . $file_locations[ IntVal( $_GET[ 'id' ] ) ] );
    ?>


    You could also read the file contents and return it to client
    (giving correct headers first) but this way you'll block download
    resuming etc. The main flaw of the solution above is that the
    user can get the file location and then use it bypassing
    download_file.php.
    A good idea would be to get file locations from some database
    (not PHP array) and to store somewhere information about
    download performed (for download stats).


    Hilarion
    Hilarion Guest

  4. #4

    Default Re: how to hide the url of a file for downl load?

    Hilarion wrote: 
    >
    >
    >
    >
    > <?php
    > // download_file.php
    > $file_locations = array(
    > 1 => 'my/location/file1.zip',
    > 2 => 'my/dislocation/file2.doc',
    > 1123 => 'some/important/file.dbf'
    > );
    >
    > Header( 'Location: http://my.server.com/' . $file_locations[ IntVal(
    > $_GET[ 'id' ] ) ] );
    > ?>
    >[/ref]

    This won't help much, since the real url is passed to the client and
    that is what the OP wanted to avoid.

    Regards
    Stefan

     
    Stefan Guest

  5. #5

    Default Re: how to hide the url of a file for downl load?

    > > <?php [/ref]
     

    She didn't write she wants to hide it before client. She only
    wanted to hide it before the user. Most client apps do not present
    the URL for the downloaded file so the above solution is OK in most
    cases.


    Hilarion
    Hilarion Guest

  6. #6

    Default Re: how to hide the url of a file for downl load?

    Hilarion wrote: 
    >> IntVal( > $_GET[ 'id' ] ) ] ); [/ref]
    >

    >
    >
    > She didn't write she wants to hide it before client. She only
    > wanted to hide it before the user. Most client apps do not present
    > the URL for the downloaded file so the above solution is OK in most
    > cases.
    >[/ref]

    Well at least if you're using a download manager you'll get the URL.
    Never mind, I let it up to her. But it is also possible to provide a
    resume function by the download script.

    Regards
    Stefan
     
    Stefan Guest

  7. #7

    Default Re: how to hide the url of a file for downl load?

    > [...] it is also possible to provide a resume function by the download script.

    I assumed that it's possible but I suppose it's quite hard to code.
    If you know some PHP code that does it, then please post it here (i've been
    looking for something like that for long time). If you know any way how
    to use Apache abilities from PHP to do it, then it's even better.


    Hilarion



    Hilarion Guest

  8. #8

    Default Re: how to hide the url of a file for downl load?

    Hilarion wrote: 
    >
    >
    > I assumed that it's possible but I suppose it's quite hard to code.
    > If you know some PHP code that does it, then please post it here (i've been
    > looking for something like that for long time). If you know any way how
    > to use Apache abilities from PHP to do it, then it's even better.
    >
    >
    > Hilarion
    >
    >
    >[/ref]
    Its all about headers:

    For example sending this to a client:

    HTTP/1.1 200 OK
    Connection: close
    Date: Tue, 19 Oct 2004 15:11:23 GMT
    Accept-Ranges: bytes
    Last-Modified: Sun, 26 Sep 2004 15:52:45 GMT
    ETag: "47febb2cfd76c41:2062"
    Cache-Control: private
    Content-Type: application/x-zip-compressed
    Content-Length: 2844011

    let the client know that resuming is possible, and for example the
    client sends the following back:

    GET http://192.168.100.100/download.zip HTTP/1.0
    Range: bytes=822603-
    Unless-Modified-Since: Sun, 26 Sep 2004 15:52:45 GMT
    If-Range: "47febb2cfd76c41:2062"

    Then you send something like this:

    HTTP/1.1 206 Partial Content
    Content-Range: bytes 822603-2844010/2844011
    Accept-Ranges: bytes
    Last-Modified: Sun, 26 Sep 2004 15:52:45 GMT
    ETag: "47febb2cfd76c41:2062"
    Cache-Control: private
    Content-Type: application/x-zip-compressed
    Content-Length: 2021408


    As you mentioned its kinda wasteful to keep track of what is sent to the
    script but it is not that difficult.


    As well on the fpassthru function page in the php manual:

    "
    nexz2004 at yahoo dot com
    21-May-2004 09:30
    also it is possible to make your php script resume downloads, to do this
    you need to check $_SERVER['HTTP_RANGE'] which may contain something
    like this
    "bytes=10-" - resume from position 10, and to end of file

    when sending response it is also needed to send with headers
    Accept-Ranges: bytes
    Content-Length: {filesize}
    Content-Range: bytes 10-{filesize-1}/{ffilesize}

    hope its usefull
    "


    On this address you will find a complete example of such a code:

    http://de2.php.net/fread


    Regards
    Stefan
    Stefan Guest

  9. #9

    Default Re: how to hide the url of a file for downl load?

    Stefan Rybacki wrote:
     [/ref][/ref]
     [/ref]
     

    I know that :)

     

    Thank you for the link (I'm using PHP manual in CHM file so it lacks many
    user comments, but it's faster and makes searching easier) and for reminding
    HTTP header fields related to the problem.


    Hilarion
    Hilarion Guest

Similar Threads

  1. How to load/show/hide GRAPHIC SYMBOL with Actionscript?
    By cp in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: October 1st, 04:39 PM
  2. popup menus won't hide - PVII show/hide layers behaviour
    By Jonibean in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: December 29th, 08:24 PM
  3. Code to hide Flash File in case user has old player....
    By jegg123 in forum Macromedia Flash Ad Development
    Replies: 1
    Last Post: September 12th, 10:41 PM
  4. Director .exe file - Hide VERSION number possible?
    By DrLynx in forum Macromedia Director Basics
    Replies: 0
    Last Post: April 6th, 10:26 AM
  5. Hide and show objects in a swf file
    By Jota webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 2
    Last Post: November 10th, 12:53 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139