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 tim开发者_运维技巧e
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
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
Could you store the pictures in a SQL database?
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.
精彩评论