簡體   English   中英

如何在Codeigniter中顯示圖像

[英]How to display image in codeigniter

我想顯示圖像表單視圖

<img src="<?php echo base_url('images/login.jpg'); ?> " width="90" height="40" />

但這是行不通的。 當我寫

<img src="images/login.jpg " width="90" height="40" />

它在瀏覽器中顯示,但不在本地主機中顯示

我的.htaccess中有問題嗎

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /helloworld/

    # Disable rewrite for valid directory/files    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d 

    #map all request urls to a specific controller method
    RewriteRule ^(.*)$ index.php?/{controller}/{method}/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

請任何人幫助我

如果您只想在htaccsess文件中訪問沒有“ index.php”的文件,則應該是這樣的

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /helloworld/

    # Disable rewrite for valid directory/files
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    #map all request urls to a specific controller method
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

並且images文件夾必須位於項目的根目錄中。 希望我的回答可以對您有所幫助:D

此方法與.htaccess文件無關,並放置index.php

<img src="<?php echo base_url('index.php/images/login.jpg'); ?> " width="90" height="40" />

但是,如果你仍然想使用.htaccess文件,然后替換所有代碼.htaccess這個代碼文件:

RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

然后,您可以訪問沒有index.php

<img src="<?php echo base_url('images/login.jpg'); ?> " width="90" height="40" />

像這樣

<img src="<?php echo base_url(); ?>images/login.jpg" width="90" height="40" />

以及config/config.php

$config['base_url'] = '';

你的形象應該放在第一位

application
images
    login.jpg
system
index.php

您有與廣告相關的任何班級名稱嗎? 如果是的話,瀏覽器的廣告塊擴展名往往會隱藏圖像,在我的項目中面臨類似的問題,也只是禁用測試擴展名或更改類名。

只是一個猜測。 希望對您有幫助。

不要忘記在控制器構造函數上導入url helper。

function __construct()
{
    parent::__construct();
    $this->load->helper('url');
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM