图像不可读的codeigniter网站?可读、图像、网站、codeigniter

2023-09-02 11:41:10 作者:婲開婲落自相惜

(这可能属于对serverfault,因为Apache是​​导致错误;如有需要请移动)

我有一个codeIgniter网站,我想要显示的图像。我的图像存储在点燃/应用/图像文件夹(其中点火,实际上是codeIgniter根装),以及这里是我的code:

 < TD>< IMG SRC =< PHP的回声BASE_URL();?>应用程序/图片/ unrav.png/>< / TD>
 

渲染源产生以下网址:

 < TD>< IMG SRC =HTTP://localhost/ignite/application/images/unrav.png/>< / TD>
 

这应该工作,但它不显示图像,当我直接去了网址,我得到以下错误:

 访问被禁止!

您没有权限访问请求的对象。它可以是读保护或不被服务器读取。

如果你认为这是一个服务器错误,请与网站管理员联系。

错误403

本地主机
孙二零一一年二月二十零日下午4时31分02秒CST
阿帕奇/ 2.2.14(Uni​​x的)DAV / 2了mod_ssl / 2.2.14的OpenSSL / 0.9.8l PHP / 5.3.1 mod_a preq2-20090110 / 2.7.1的mod_perl / 2.0.4的Perl / v5.10.1
 
手机B站更改下载目录,显示目录不可读该怎么办

我检查图像权限,并将其设置为777(读,写,所有者,组和公开执行)。这是我的本地开发服务器上,而如果我去一个文件/打开我的浏览器和浏览文件系统映像,它正确地显示,所以我知道图像不会损坏或任何东西。谁能给我发生了什么想法?我已经做了严格的发展到了这一点,没有服务器管理员,所以我一点也不熟悉的东西Apache的问题。

编辑补充Apache的错误日志:

  [太阳2月20日16点26分07秒2011] [错误] [客户127.0.0.1]客户端通过服务器配置否认中:/ opt / LAMPP / htdocs中/点燃/应用/图片/unrav.png
 

EDITED再次添加的.htaccess:

  RewriteEngine叙述上
的RewriteCond $ l ^(指数 .PHP |图片|机器人 .TXT | CSS)!
aRewriteRule ^(。*)$ /index.php/$1 [L]
 

EDITED再次以添加的RewriteBase之后加入Apache日志:

  [太阳2月20日十七时02分19秒2011] [声明] suEXEC的激活机制(包装中:/ opt / LAMPP /斌/ suexec的)
[太阳2月20日17点02分19秒2011] [提醒] RSA服务器证书是一个CA证书(BasicConstraints:?CA = = TRUE)
[太阳2月20日17点02分19秒2011] [提醒] RSA服务器证书的CommonName(CN)'localhost'的不匹配的服务器名!?
[太阳2月20日17点02分19秒2011] [声明]摘要:生成的秘密摘要认证...
[太阳2月20日17点02分19秒2011] [声明]摘要:完成
[太阳2月20日17时02分二十秒2011] [提醒] RSA服务器证书是一个CA证书(BasicConstraints:?CA = = TRUE)
[太阳2月20日17时02分二十秒2011] [提醒] RSA服务器证书的CommonName(CN)'localhost'的不匹配的服务器名!?
[太阳2月20日17时02分二十秒2011] [声明]的Apache / 2.2.14(Uni​​x的)DAV / 2了mod_ssl / 2.2.14的OpenSSL / 0.9.8l PHP / 5.3.1 mod_a preq2-20090110 / 2.7。 1的mod_perl / 2.0.4的Perl / v5.10.1配置 - 恢复正常运营
 

解决方案

我的猜测是,你的.htaccess文件没有正确设置为没有的重写图像文件的请求。当你提供codeIgniter从什么地方比在服务器的根目录其他(即 /点燃/ )的标准CI .htaccess文件可能不匹配的图像文件夹为了不把它改写为指向的index.php。

是什么在你的.htaccess文件?是否有RewriteBase指令?请参见 mod_rewrite的维基CI进入,看看是否能得到任何线索。或者只是尝试

 的RewriteBase /点燃/
 

...刚过RewriteEngine叙述,看看会发生什么。

如果它有助于理解发生了什么,标准的CI的.htaccess看起来是这样的:

  RewriteEngine叙述上
的RewriteCond $ l ^!(指数 .PHP |图片|表图片| JS |机器人 .TXT | CSS)
重写规则^(。*)$ /index.php/$1 [L]
 

主要活动是重写规则,这将引发的一切,在到index.php文件的末尾。这样,您不必有的index.php 在你的CI的URL开始,而不是 HTTP就是:// WWW .example.com的/的index.php /控制器/法,你可以只写 http://www.example.com/controller/method

它是通过采取一切从路径( ^(。*)$ )和index.php文件的末尾改写。括号中的图案 ^(。*)$ 是一组。每个小组被赋予了一个数字,你可以用它来反向引用在其他地方使用$ N。在这种情况下,只有一组,你可以在其他地方称其为 $ 1 。所以:

 重写规则^(。*)$ /index.php/$1 [L]
 

指抢一切(。*)从开始(^)到路径末端($),并将其命名为$ 1(因为它是在括号中的第一个前pression),然后重写的路径作为/index.php/$1,即推一切上的index.php的末端。

现在,这对大多数事情 - 所有的控制器和方法 - 但如果你有,你想为一些静态文件,如图片,你的不的想要去通过你的控制器,即你的index.php。这是一个很大更快的只是服务于他们,而不需要通过PHP的。

这就是在的RewriteCond 进来在这种情况下:

 的RewriteCond $ l ^(指数 .PHP |图片|表图片| JS |机器人 .TXT | CSS)!
 

...就是我们要说的是,只运行下面的重写规则,如果其模式(同样, $ 1 )的没有第一组的( !)开始( ^ )事物的清单如下:的index.php 图像,表图片,爵士,robots.txt的,或CSS。

这就是图像获得如何服务 - 而不是网址被重写的重写规则,如果有一个呼叫控制器,就像一切,经历的index.php,他们忽略,因为的RewriteCond 有效地写着不打扰重写了以'形象'的任何路径,然后由阿帕奇为正常。

希望这可以帮助您去对付什么的。htaccess的事情。

(This may belong on serverfault, since apache is causing the error; please move if necessary.)

I have a CodeIgniter site that I'm trying to display an image in. My image is stored in the ignite/application/images folder (where ignite is actually the root install of CodeIgniter), and here's my code:

 <td><img src="<?php echo base_url(); ?>application/images/unrav.png" /></td>

The rendered source produces the following URL:

<td><img src="http://localhost/ignite/application/images/unrav.png" /></td> 

This SHOULD work, but it's not displaying the image, and when I go to the URL directly, I get the following error:

Access forbidden!

You don't have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

Error 403

localhost
Sun 20 Feb 2011 04:31:02 PM CST
Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1

I've checked the image permissions and set them to 777 (read, write, execute for owner, group, and public). This is on my local dev server, and if I go a File/Open in my browser and navigate through the file system to the image, it does display correctly, so I know the image isn't corrupted or anything. Can anyone give me an idea of what's happening? I've strictly done development up to this point, no server admin, so I'm not at all familiar with what apache's problem is.

EDITED to add apache error log:

[Sun Feb 20 16:26:07 2011] [error] [client 127.0.0.1] client denied by server configuration: /opt/lampp/htdocs/ignite/application/images/unrav.png

EDITED AGAIN to add .htaccess:

RewriteEngine on
RewriteCond $1 !^(index.php|images|robots.txt|css)
aRewriteRule ^(.*)$ /index.php/$1 [L]

EDITED YET AGAIN to add apache log after adding RewriteBase:

[Sun Feb 20 17:02:19 2011] [notice] suEXEC mechanism enabled (wrapper: /opt/lampp/bin/suexec)
[Sun Feb 20 17:02:19 2011] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Sun Feb 20 17:02:19 2011] [warn] RSA server certificate CommonName (CN) `localhost' does NOT match server name!?
[Sun Feb 20 17:02:19 2011] [notice] Digest: generating secret for digest authentication ...
[Sun Feb 20 17:02:19 2011] [notice] Digest: done
[Sun Feb 20 17:02:20 2011] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Sun Feb 20 17:02:20 2011] [warn] RSA server certificate CommonName (CN) `localhost' does NOT match server name!?
[Sun Feb 20 17:02:20 2011] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations

解决方案

My guess is that your .htaccess file isn't set up properly to not rewrite requests for image files. As you're serving CodeIgniter from somewhere other than the server root (i.e. /ignite/) the standard CI .htaccess file probably isn't matching the images folder in order not to rewrite it to point at index.php.

What's in your .htaccess file? Is there a RewriteBase directive? See the mod_rewrite wiki CI entry to see if you can get any clues. Or just try

RewriteBase /ignite/ 

...just after the RewriteEngine On and see what happens.

If it helps understand what's happening, the standard CI .htaccess looks something like this:

RewriteEngine on
RewriteCond $1 !^(index.php|images|table-images|js|robots.txt|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

The main event is the RewriteRule, which throws everything that comes in onto the end of the index.php. This is so you don't need to have index.php at the start of your CI URLs, that is, instead of http://www.example.com/index.php/controller/method, you can just write http://www.example.com/controller/method.

It does that by taking everything from the path (^(.*)$) and rewriting it on the end of index.php. The brackets in the pattern ^(.*)$ are a group. Each group gets given a number that you can use to "backreference" it elsewhere using $n. In this case, there's only one group, and you can refer to it elsewhere as $1. So:

RewriteRule ^(.*)$ /index.php/$1 [L]

Means "grab everything (.*) from the beginning (^) to the end ($) of the path, and call it $1 (because it's the first expression in brackets). Then rewrite the path as /index.php/$1", i.e. shove everything on the end of index.php.

Now, that's fine for most things -- all the controllers and methods -- but if you've got some static files you want to serve, like images, you don't want to go through your controllers, i.e. your index.php. It's a lot faster just to serve them up without going through PHP at all.

That's where the RewriteCond comes in. In this case:

RewriteCond $1 !^(index.php|images|table-images|js|robots.txt|css)

...what we're saying is, "only run the following RewriteRule if the first group in its pattern (again, $1) doesn't (!) begin (^) with the following list of things: "index.php", "images", "table-images", "js", "robots.txt", or "css".

And that's how images get served -- instead of the URLs being rewritten by the RewriteRule as if there were a call to a controller, like everything that goes through index.php, they're ignored because the RewriteCond effectively says "don't bother rewriting any paths that start with 'images'", and then served by Apache as normal.

Hope this helps you get to grips with what's going on in the .htaccess.

 
精彩推荐