这样写法有错吗,为何写入失败?
$this->load->helper('file');$data = 'Some file data';
$addfile= base_url().'addselecter/addxml.xml';
if (!write_file($addfile,$data))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}
// CI1.63 Apache MySQL-5.0.15b php-5.2.6-Win32 一般这个问题都要把URL贴出来.
你把$addfile打印出来看一下是不是你要保存的路径
且,文件夹是否有写入权限. http://127.0.0.1/ci_website/addselecter/addxml.xml
echo $addfile;路径是没错啊 你不能把文件保存到 URL 路径上,应该是磁盘路径。 改成磁盘路径是可以的
$addfile='D:/addxml.xml';
但用网站相对路径,应该怎样写呢?
哪位朋友指教一下~/?
[ 本帖最后由 le_el 于 2008-8-4 13:47 编辑 ] APPPATH .. 这个是index.php中设置的目录:如 $system_folder = "system";
就是那个system目录..
如果system下有个addselecter/addxml.xml
那么直接是 APPPATH.'addselecter/addxml.xml'
试试
程序修改如下
$this->load->helper('file');
$data = 'Some file data';
$addfile= APPPATH.'addselecter/addxml.xml';
if (!write_file($addfile,$data))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}
// CI1.63 Apache MySQL-5.0.15b php-5.2.6-Win32
写入不成功,得出的路径怎么有点怪?
楼上的兄弟 不对哦。addselecter/addxml.xml,addselecter与system目录是平行的,就在站点根目录下。不用磁盘路径还有别的办法吗?echo APPPATH;//得如下,得出的路径怎么有点怪?
D:\PHP**\htdocs\ci_website/system/application/
echo $addfile;//得如下
D:\PHP**\htdocs\ci_website/system/application/ addselecter/addxml.xml
[ 本帖最后由 le_el 于 2008-8-4 17:33 编辑 ] 修改如下
$this->load->helper('file');
$data = 'Some file data';
$addfile= APPPATH.'./../../addselecter/addxml.xml';
if (!write_file($addfile,$data)) {
echo 'Unable to write the file';
} else {
echo 'File written!';
}
注意addselecter目录要存在. 相对路径你要自己换算,PHP 应该可以换算。
还有:正斜杠和反斜杠都可以作为路径,这没问题,好看不好看无所谓。 用$addfile= APPPATH.'./../../addselecter/addxml.xml'; 成功写入了,
谢谢 yalez,Hex.
只是用APPPATH做为目录参照,不是很方便记忆和确定目录的位置。希望能有更好的写法。
:handshake
页:
[1]