Reputation: 210
How can i display a image from outside the document root. To be precise
/ <-- root directory
/public_html/ <-- document root
/application/upload/img <-- here is the source of image
I made in codeigniter and it works but has a big delay if i try to load multiple times. I this it is in codeigniter a helper function to help me and boost my time to load the file.
I show the code what i have write:
This is in controller:
public function img($img_name){
$t = $this->getupload->Get($img_name); // here is taked from DB using MODEL
header("Pragma: public");
header("Content-type: {$t[0]['file_type']}"); // Take the file type (eg: images/jpg) from DB
header('Content-Transfer-Encoding: binary');
flush();
readfile($t[0]['full_path']); // here take the imgfile from DB
}
Upvotes: 0
Views: 1400
Reputation: 11677
if you will want your server to work, and not the code.
You should configure your apache or nginx to fetch the data from that path.
in apache htaccess you could try:
RewriteRule ^uploads/(.*)$ /var/www/application/upload/img/$1 [R=301,NC,L]
I'm not sure it will work, but this is an idea.
in nginx you can check something like this:
location /uploads/* {
try_files /var/www/application/upload/img/$query_string;
}
again I'm not sure it will work, as I'm not a servers master, but if this is what you would like to accomplish I would suggest checking that.
Upvotes: 1