Click to See Complete Forum and Search --> : d/l a file in a secure way


pelegk1
07-08-2004, 05:17 AM
i want to d/l a file
but i dont wantto let the user where the file on the server
and to prevent from him d/l file that he is not
authorized to d/l
how cna i do that?
i see in some places that when u press a link the file is bein redirected from another place,given a long string that tells which file to d/l but
the user can't take that link and byhimself to d/l that
thnaks in advance
peleg

crh3675
07-08-2004, 11:53 AM
Use this code :



$filename="pathtoyourfile";
$filetype="filetype";

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-type: ".$filetype." File");
header("Content-length: ".filesize($filename));
header("Content-Disposition: attachment; filename=".$file);

$fp=fopen($filename,"rb");
fpassthru($fp);
flush();

Tony_shu
07-10-2004, 06:18 PM
very kewl

pelegk1
07-11-2004, 12:30 AM
hi crh3675
does your code works on all browsers?
on which browsers did u had a chance to check it?

pelegk1
07-11-2004, 11:31 AM
$filetype="filetype";
???
thnaks laot
peleg

Tony_shu
07-12-2004, 01:01 AM
$filetype = filetype($filename); ... that will define the file type for you automatically :D