2010-09-08 32 views
4

有一個文件,該文件是可讀可寫,但被的fopen返回false ...PHP的fopen返回false,但文件是可讀/寫

if(is_readable($file)) echo 'readable '; 
if(is_writable($file)) echo 'writable '; 
$fp = fopen($file, 'a+'); 
var_dump($fp); 

結果是

readable writable bool(false) 

任何想法?

確定它必須是一個許可的事情,但在文件上嘗試777具有相同的結果。

+1

你1000%肯定它是一個文件,而不是一個目錄? 'error_reporting(E_ALL);'說什麼? – 2010-09-08 12:03:01

+4

1000%似乎有點矯枉過正; P – Wrikken 2010-09-08 12:05:59

+0

將錯誤報告設置爲E_WARNING並查看錯誤消息是什麼。 – jmz 2010-09-08 12:21:02

回答

16

讓我們嘗試獲取更多信息。
什麼

$file = 'p:\muh'; 

error_reporting(E_ALL); 
ini_set('display_errors', true); 
echo 'phpversion: ', phpversion(), "\n"; 
echo 'uname: ', php_uname("s r"), "\n"; // name/release of the operating system 
echo 'sapi: ', php_sapi(), "\n"; 

echo $file, file_exists($file) ? ' exists' : ' does not exist', "\n"; 
echo $file, is_readable($file) ? ' is readable' : ' is NOT readable', "\n"; 
echo $file, is_writable($file) ? ' is writable' : ' is NOT writable', "\n"; 

$fp = fopen($file, 'a+'); 
if (!$fp) { 
    echo 'last error: '; 
    var_dump(error_get_last()); 
} 
else { 
    echo "ok.\n"; 
} 

打印?

還看到:http://docs.php.net/error_get_last

+0

它是一個處理錯誤的插件 - 只是報告它無法訪問文件 - 問題是權限,因爲文件的所有者不允許php chmod - 並且該錯誤正在被壓制...... – 2010-09-09 10:34:41