download from secure archive

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Re: download from secure archive

    Hi Dani,

    PHP isn't really designed to interact with the filesystem in the same
    way that a proper htacess scheme would work. One alternative is to
    "bury" your files in a directory no-one is going to type in manually,
    like:

    [url]http://www.yourfreehost.com/~yoursite/subdirectory/2034820482309810940921834/[/url]

    Then, you can put a PHP file in the subdirectory that takes in the
    file to download, like


    [url]http://www.yourfreehost.com/~yoursite/subdirectory/downloader.php?file=doc1.doc[/url]

    and have the downloader.php file get doc1.doc from the
    2034820482309810940921834 directory and stream its output. The
    "gotcha" in all this is, of course, you need to make sure you return
    the right mime types so that the receiving browser gets a *.doc file
    instead of a php file. Something like:

    <?PHP header("Content-Type: application/vnd.ms-word"); ?>
    <?PHP header("Content-disposition: attachment; filename=doc1.doc"); ?>

    should do the trick in the above example.

    Cheers,
    Robert

    [email]Robert@PeakePro.com[/email]
    [url]http://www.peakepro.com[/url]

    [email]jeckyll@virgilio.it[/email] (Daniele) wrote in message news:<940a6f3e.0307280121.2b2fb3e3@posting.google. com>...
    > Hi all,
    > I'm doing a php web site, after implementing a sicure access to
    > download some file stored in a web server folder. My site is in a free
    > hosting server and I haven't rights to modify any web service
    > configuaration to allow or deny access to specify folder. I'm looking
    > for a secure method to hide the directory where are stored important
    > documents in order to allow the access only to authorized person that
    > are logged in the previous php page.
    > Any Idea
    >
    > Thanks a lot in advance
    >
    > Dani
    Robert Peake Guest

  2. Similar Questions and Discussions

    1. Archive Download Server is Down!
      I'm trying to download version 7 of Flash Player, but the server is down! Why? I can't install version 8 or any other version. What's the deal...
    2. Secure Area Download
      Hi i have this site http://www.aprocre.org.ve you can see in the right top corner a login. Thats login is only for the members that can (when they...
    3. Secure FTP File download + c#
      Hi I need the ability to download a file from a secure ftp sight using c#. Has anybody got free code or at least point me in the right direction....
    4. SA-FileUp Secure Download Issue - Please HELP!
      Hi Everyone, I was wondering if anyone has ever successfully used SA-FileUp's download feature. I am being forced to change from...
    5. Download secure web page
      http://www.aspfaq.com/show.asp?id=2257
  3. #2

    Default Re: download from secure archive

    Hi Robert thank you for your hints,
    I tried to make a download manager so but it doesn't work.
    My script is:

    $file="mysubdir/myfile.doc";
    if ($fd = fopen ($file, "r")){

    $size=filesize($file);
    $fname = basename ($file);

    header("Pragma: ");
    header("Cache-Control: ");
    header("Content-Type: application/vnd.ms-word");
    //header("Content-type: application/octet-stream"); <-- I also
    tried this
    header("Content-Disposition: attachment;
    filename=\"".$fname."\"");
    header("Content-length: $size");

    while(!feof($fd)) {
    $buffer = fread($fd, 2048);
    print $buffer;
    }
    fclose ($fd);
    exit;
    }

    I tried also this:

    $file="fileName.doc";
    header("Pragma: ");
    header("Cache-Control: ");
    header("Content-Type: application/vnd.ms-word");
    $fd = fopen($file,'r');
    fpassthru($fd);


    I get always the content of the file in the browser without prompting
    the save file window.

    Do you have any hint?

    Thanks a lot
    Dani
    Daniele Guest

  4. #3

    Default Re: download from secure archive

    Hi Danielle,

    You can not test your code by typing in the URL directly. The content
    and disposition headers will only work properly when called from a
    link.

    The following code:

    <?PHP
    if ($doc=="resume.doc") {
    header("Content-type: application/vnd.ms-word");
    header("Content-disposition: attachment; filename=$doc");
    readfile("../resume.doc");
    } else {
    print "<a href=\"getdoc.php?doc=resume.doc\">click me</a>";
    }
    ?>

    lives on my site:

    [url]http://www.peakepro.com/workbench/getdoc.php[/url]

    open it up and click on the link to see how it works.

    Cheers,
    Robert

    [email]Robert@PeakePro.com[/email]
    [url]http://www.peakepro.com[/url]
    Robert Peake Guest

Posting Permissions

  • You may not post new threads
  • You may 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