簡體   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