Re: how to provide download of files mow in documentroot

From: Date: Mon, 29 Mar 2010 12:13:10 +0000
Subject: Re: how to provide download of files mow in documentroot
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-303595@lists.php.net to get a copy of this message
Top posting sucks, so I'll answer the post somewhere down there. <SCNR> 2010/3/29 Devendra Jadhav <devendra.in@gmail.com> > Then you can do file_get_contents within PHP. or any file handling > mechanism. > >> On Mon, Mar 29, 2010 at 1:00 AM, ebhakt <im@ebhakt.com> wrote: > >>> Hi > >>> i am writing a web application in php > >>> this webapp primarily focuses on file uploads and downloads > >>> the uploaded files will be saved in a folder which is not in document > >>> root > >>> and my query is how will i be able to provide download to such files > not > >>> located in document root via php > >>> > Try something like that <?php $content = file_get_contents($filename); $etag = md5($content); header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($filename)).' GMT'); header('ETag: '.$etag); header('Accept-Ranges: bytes'); header('Content-Length: '.strlen($content)); header('Cache-Control: '.$cache_value); // you decide header('Content-type: '.$should_be_set); echo $content; exit; ?> Depending on the $filesize, you should use something else than file_get_contents() (for example fopen/fread). file_get_contents on a huge file will exhaust your webservers RAM. Regards

« previous php.general (#303595) next »