Page 1 of 1

download file

Posted: Wed Aug 17, 2005 1:51 pm
by nincha
any way to allow some one to download a file without letting them know the directory the file is located on the server?

Posted: Wed Aug 17, 2005 2:44 pm
by Fractal
You could use apache and direct the link to something like

downloads.php?id=1

And store the links in a database then using $_GET and a mysql query to retrieve the data.

Posted: Wed Aug 17, 2005 4:19 pm
by nincha
how would that initialize the download?

Posted: Wed Aug 17, 2005 4:21 pm
by neophyte

Code: Select all

if(is_file('/home/path/to/directory/'.$gallery."/".$file)){
    header("Cache-control: private");
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=".$file);
    header("Content-length: ".filesize($gallery."/".$file)."\n");
    //send file contents
    $fp=fopen($gallery."/".$file, "r");
    fpassthru($fp);
}
I found this snippet of code on this board today -- patrikG posted it. I'm using it to download images. But I'm sure it could be easily adapted for txt files or what not.

Hope that helps

Posted: Wed Aug 17, 2005 5:35 pm
by Fractal
nincha wrote:how would that initialize the download?
Depends on what they're downloading.. o_O

Posted: Wed Aug 17, 2005 6:10 pm
by nincha
thnx neophyte, im curious about possible file corruption through this method of file download.

Posted: Wed Aug 17, 2005 6:13 pm
by timvw
I've always done the downloading like in the file (doing a little effort to send the right content type)

http://timvw.madoka.be/programming/php/download.txt

AFAIK there is no problem with file corruption. But, you could always generate an MD5 file so your users can verify it...

Posted: Wed Aug 17, 2005 6:15 pm
by feyd
....MD5 and/or SHA1 and/or SHA256 ;)


teehee... I couldn't resist. :lol:

Posted: Wed Aug 17, 2005 7:28 pm
by Ambush Commander
Actually, using SHA256 wouldn't necessarily be a good idea unless you have a large set_time_limit and you're caching the hashes. When you start dealing with message digests of files in the megabytes range, a pure PHP solution is just too slow.

Actually, there's no reason why you shouldn't be caching the hashes. SHA256 will just take a lot longer.

Posted: Tue Aug 23, 2005 8:36 pm
by nincha
cant seem to get this method of downloading to work correctly under https