3 回答

TA貢獻1851條經驗 獲得超3個贊
在windows瀏覽器地址直接輸入該php文件
檢查執行結果是否如下警告:
Warning: fopen(xxx.txt): failed to open stream: Permission denied in /usr/local/www......
這是因為默認下selinux是開啟的,會阻值修改文件。
查看SELinux狀態:
1、/usr/sbin/sestatus -v ##如果SELinux status參數為enabled即為開啟狀態
SELinux status: enabled
2、getenforce ##也可以用這個命令檢查
關閉SELinux:
1、臨時關閉(不用重啟機器):
setenforce 0 ##設置SELinux 成為permissive模式
##setenforce 1 設置SELinux 成為enforcing模式
2、修改配置文件需要重啟機器:
修改/etc/selinux/config 文件
將SELINUX=enforcing改為SELINUX=disabled
重啟機器即可
另外,如果以上還是不能解決的話要設置一下目錄的權限策略
chcon -R -t httpd_sys_content_t /home/html

TA貢獻1820條經驗 獲得超2個贊
翻譯:
file_put_contents(/PHP/admin/tp/runtime/temp/71dafaa2a0ea0d586666de9d67f301a7.php):無法打開流:權限被拒絕
解決辦法:
文件或目錄需要的權限是很大的,如果你只給一般權限肯定是不行的,通常都是給runtime權限:777

TA貢獻1806條經驗 獲得超5個贊
1、查看一下你寫入的文件路徑是否正確
2、那個文件是否有寫入的權限
3、file_put_contents方法是否存在
依據你給的代碼圖片,將其修改了一下,你試試看看行不行:
<?php if ( $_POST [ 'Submit' ] == '注冊' ){ $a = 'file.txt' ; $c = $_POST [ 'user' ]; // 如果$c是一個數組,先foreach循環 - 組裝成需要寫入發內容 if ( is_array ( $c )){ foreach ( $c as $k => $v ) { $html = '這是寫入的內容' . "\r\n" ; $html .= '寫入的內容要是字符串!' . "\r\n" ; $html .= '.....' ; } $c = $html ; } // 寫入 if ( file_exists ( 'file_put_contents' )){ file_put_contents ( $a , $c ); } else { $handle = fopen ( $a , 'w+' ); fwrite( $handle , $c ); fclose( $handle ); } } ?> |
- 3 回答
- 0 關注
- 973 瀏覽
添加回答
舉報