Forum Moderators: coopster

Message Too Old, No Replies

Secure Downloading

Best Way To Achieve Secure Downloading in PHP

         

Sekka

12:18 pm on Oct 27, 2006 (gmt 0)

10+ Year Member



Hi,

I am setting up a mini file upload/retrieve system.

The way I am tackling this is having all the files stored outside of the htdocs folder, a.k.a. ../files/, so they can't be accessed publically.

Now I use a similar method for storing images and I use PHP to read and send out the images so people can view them.

e.g.

$img = @imagecreatefromjpeg ("../tmp/{$thumb}");
header("Content-type: image/jpeg");
imagejpeg($img);
imagedestroy($img);
exit ();

What I can't seem to figure out is how to achieve this with ordinary files. Firstly, I would need to get the MIME type for the header, and secondly I would need read and output the file.

Firstly, is this possible? Secondly, is there a better way of doing it?

Thanks.

Sekka

12:31 pm on Oct 27, 2006 (gmt 0)

10+ Year Member



Looks like I answered my own question,,

header ("Content-Type: application/force-download");
header ("Content-Disposition: attachment; filename=\"{$filename}\"");
readfile ($filename);
exit ();

Thanks anyway.