Top posting sucks, so I'll answer the post somewhere down there.
<SCNR>

2010/3/29 Devendra Jadhav <devendra...@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 <i...@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

Reply via email to