ivan
ivan

Reputation: 63

How do i display image located outside the public folder in php using file:// protocol

I have a table in my datebase which contains only path to the images. the path outside the public folder, the path is like this (/home/username/folder/sudfolder/datefolde/images) the date folder will always be the name of the current date?

what is the best php function to use to display the images? and how do i do it?

i am using codeigniter,centos 7, mysql and nginx

Upvotes: 1

Views: 306

Answers (1)

Alexandr Makarov
Alexandr Makarov

Reputation: 46

First of all try to avoid using PHP if possible, its not a good idea to execute PHP interpreter for every image request, as it requires too much resources. Instead create symlink in the public directory.

In case you can not avoid php, try using X-Accel-Redirect header for Nginx

header("X-Accel-Redirect: /files/" . $path);

Or in case you use Apache:

header("X-Sendfile: $filename");

If these options are not available too, use readfile() php function

Upvotes: 1

Related Questions