本来没有考虑这个问题,是对绝对路径下的文件进行读写的时候报了错,使用的是fopen()函数
fopen("c:\\cmd.txt","r");
出现以下错误提示:
Warning: fopen("c:\\cmd.txt","r") - No such file or directory in
查了下,可能是没有给PHP读写文件的权限。需要用到open_basedir进行配置
在php.ini文件中配置:
上面这条指令设置了php脚本可以访问的两个目录,注意在windows系统中目录之间用分号隔开
因为我用的是Apache服务器,查了有关资料还可在Apache的配置文件中进行设置。 Apache虚拟主机配置
1、如果开启了虚拟主机,可以在Apache\Apache24\conf\extra\httpd-vhosts.conf中配置
<VirtualHost *:80>
DocumentRoot "D:/www"
ServerName 121.com
<Directory "D:/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
php_admin_value open_basedir "D:\www;E:\history"
</Directory>
</VirtualHost>
php_admin_value open_basedir “D:\www;E:\history”添加了这一句
2、如果没有开启虚拟主机,可以在Apache\Apache24\conf\httpd.conf设置
加上修改Apcahe配置文件
php_admin_value open_basedir “D:\www;E:\history”
引号中的地址是允许PHP访问的地址
重启Apache后,一般情况就可以解决上述问题了。
由于使用的YII框架中用到了session ,而加载网页的时候出现了验证码出现不了的情况。
验证码出现不了
网上查了很多资料,终于找到了,谢谢这位楼主打开
原因:
由于用到session,所以需要允许访问session的地址,
首先设置session存放地址 session.save_path
可以根据自己的需要确定存放的路径
然后重启Apache
验证码可以正确出现。
写在最后
我开启权限之后,可以自由读写,然后我把允许访问的文件夹删掉了,如上面E:/history,我删掉了history。
开始报错
is_dir(): open_basedir restriction in effect. File(E:\history\cmdsd) is not within the allowed path(s): (D:\www;E:\history) in
mkdir(): open_basedir restriction in effect. File(E:\history) is not within the allowed path(s): (D:\www;E:\history) in
fopen(): open_basedir restriction in effect. File(E:\history\cmdsd) is not within the allowed path(s): (D:\www;E:\history) in
我一开始很疑惑,怎么刚才还可以执行,现在不行了。
其实原因是没有E盘的根目录的访问权限,故不能操作了。之前是因为有history文件夹本来就存在,然后其子目录都可以访问,就顺其自然的完成了创建文件夹和文件的工作。
参考文章
http://blog.163.com/sdhhqb@126/blog/static/63705537201451983341975/
http://blog.csdn.net/jincenlong58/article/details/7517370
https://www.oschina.net/question/226383_117409