php配置open_basedir後及Apache對應配置 和Yii驗證碼無法出現解決方案

來源:互聯網
上載者:User

本來沒有考慮這個問題,是對絕對路徑下的檔案進行讀寫的時候報了錯,使用的是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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.