如何引用外部文件?
本帖最后由 consatan 于 2010-1-24 20:01 编辑在VIEW的print.php页面中需要显示条形码,条形码的显示是通过类似
<img src="setCode.php?text=123456" />
这样的形式展示出来的
在未部署CI的环境中,我是将所有php页面都放在同一目录下,然后在print.php页面中直接使用上面那段代码就能显示出条形码了
现在要部署到CI上,我将print.php放到view中,将显示条形码所需的其他php文件放在同一层目录下
controller中用$this->load->view('print');的形式展示print.php
这样显示不了条形码
因为我使用.htaccess定义了外部文件的位置在web根目录下
如,我引用图片、css或js的时候是这样写的src="http://servername/img/img.jpg"
这样是可以正常使用的
于是我想说用类似方法,在web根目录下建立util文件夹,然后把那些条形码相关的php都放这里,但...发现这样用不了...
所有用到这些php的地方都修改地址了,用不了,最后发现直接用http://servername/img/img.jpg的方法能访问图片和js等,但用
http://servername/util/setCode.php
提示404错误...
我该如何引用这些文件呢??
刚测试了下,发现exe或dll这类的文件也无法用类似方法访问...
我已经在.htaccess添加了exe和dll的例外了啊..
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|img|exe|dll|xpi|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1
而且也重启apache服务器了 RewriteCond $1 !^(index\.php|images|js|css|img|exe|dll|xpi|robots\.txt)
这里只是排除根目录下的目录和文件,不包含任何其他目录和文件名。
请查看 Apache 手册。
PS: CI 引入外部类库,请参考“CI 引入 Zend Framework”的方法。 RewriteCond $1 !^(index\.php|images|js|css|img|exe|dll|xpi|robots\.txt)
这里只是排除根目录下的目录和 ...
Hex 发表于 2010-1-24 20:17 http://codeigniter.org.cn/forums/images/common/back.gif
我的web根目录D:\www
.htaccess文件在 D:\www\.htaccess
图片放在D:\www\img\xxx.png
js放在 D:\www\js\xxx.js
CI的配置文件存放在 D:\www\CI\application\config\config.php
我的.htaccess就是我主楼帖的那段
我通过访问
http://localhost/img/xxx.png或http://localhost/js/xxx.js
可以成功,我将xxx.png复制到
D:\www\xxx.png
通过访问
http://localhost/xxx.png
却提示404错误
为了测试,我还特意在img目录下新建了一层
D:\www\img\bg\bg.gif
然后访问
http://localhost/bg/bg.gif
也可以访问成功哦...
CI引用外部库类的方法我试试看先{:3_64:} RewriteCond 的具体用法楼主还是看看 Apache 手册吧。呵呵 http://servername/util/setCode.php
将setcode.php的内容封装成一个单独的controller,
Setcode extends Controller{
function render()
{
// 你的条码图片渲染代码
}
}
访问http://servername/setCode/render?foo=bar 后来我直接将第三方的条形码类库放到CI根目录下(util文件夹中)
目录结构
despatch
├─application
│├─config
│├─controllers
│├─errors
│├─helpers
│├─hooks
│├─language
│├─libraries
│├─models
│└─views
├─cache
├─codeigniter
├─database
│└─drivers
│ ├─mssql
│ ├─mysql
│ ├─mysqli
│ ├─oci8
│ ├─odbc
│ ├─postgre
│ └─sqlite
├─libraries
├─logs
├─plugins
└─scaffolding
├─images
└─views
util
然后在.htaccess文件中如下编辑
RewriteEngine on
RewriteCond $1 !^(index\.php|img|js|sound|util|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1
之后使用<img src="<?php echo base_url().'util/setCode.php?text='156457 ?>" />
这样的方式就可以了...
页:
[1]