problem showing pictures stored outside web root folder

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-04-28T19:22:54Z Indexed on 2010/04/28 19:27 UTC
Read the original article Hit count: 366

Filed under:
|

On a website users can upload pictures. For security reasons these are stored outside the webroot (public_html) folder. When I need to display the picture, I send the headers and have "readfile" read and output the picture data, like so:

header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header('Content-type: image/jpg');
header('Content-Length: ' . $filesize);

readfile($path_url . '/' . $photo);

This works great, but the site is growing and this is starting to be a burden on the server.

Question: is there a way to send the picture or picture data to the user, without the server first having to load the picture (obviously with the picture still being stored outside the webroot folder)?

Thanks!

David

© Stack Overflow or respective owner

Related posts about php

Related posts about picture