Re: download pdf using php script

From: Date: Thu, 16 Sep 2004 15:06:48 +0000
Subject: Re: download pdf using php script
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-196867@lists.php.net to get a copy of this message
Hi, Thursday, September 16, 2004, 4:51:51 PM, you wrote: a> Hello PHP Users, a> I have files (that protected from direct download) and I put it a> outside public_html/ directory (outside web server directory). a> and the people from outside could access the file by typing: a> www.myweb.com/download.php?filename=xzy.pdf a> can someone give me hint how to do this ? a> thank u a> -- a> Best regards, a> adwin a> www.kuya-kuya.net Something like this <?php //need to be careful of ../ in filename so use basename $filename = "/path/to/file/".basename($_GET['filename']); if(file_exists($filename)){ $len = filesize($filename); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=foo.pdf"); readfile($filename); } ?> -- regards, Tom

« previous php.general (#196867) next »