繁体   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