繁体   English   中英

我如何在根目录外部的Codeigniter中显示图像

[英]How can i display a image in codeigniter outside root directory

如何从文档根目录外部显示图像。 确切地说

/ <-- root directory
/public_html/ <-- document root 
/application/upload/img <-- here is the source of image

我在codeigniter中制成,它可以工作,但是如果我尝试多次加载,则会有很大的延迟。 我这是在codeigniter中的一个辅助函数,可以帮助我并增加我的文件加载时间。

我向代码显示我编写的内容:

这在控制器中:

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
}

如果您想让服务器正常工作,而不是代码。

您应该将apache或nginx配置为从该路径获取数据。

在Apache htaccess中,您可以尝试:

RewriteRule ^uploads/(.*)$ /var/www/application/upload/img/$1 [R=301,NC,L]

我不确定它是否会起作用,但这是一个主意。

在nginx中,您可以检查如下内容:

location /uploads/* {
    try_files /var/www/application/upload/img/$query_string;
}

再次,我不确定它是否可以工作,因为我不是服务器主服务器,但是如果您要完成此操作,建议您进行检查。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM