David
David

Reputation: 11

problem showing pictures stored outside web root folder

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

Upvotes: 1

Views: 1027

Answers (3)

webbiedave
webbiedave

Reputation: 48887

You can look into mod_xsendfile, an apache module that can sometimes be helpful in situations like yours. Otherwise, you may need to look into implementing a dedicated media server.

Upvotes: 0

Your Common Sense
Your Common Sense

Reputation: 158009

If your problems really come from this very place and you can't use HTTP caching, there is a solution, a proxy webserver. nginx with X-Accel-Redirect or lighttpd with X-Sendfile headers

Upvotes: 1

ghoppe
ghoppe

Reputation: 21804

Could you store the pictures in a SQL database?

Upvotes: 0

Related Questions