嗨,當我執行此代碼沒有發生在瀏覽器中,但是當我刪除與明星線,內容打印正確,最新錯誤?問題與fopen和fwrite
/////////////////
$documentroot=$_SERVER['DOCUMENT_ROOT'];
$handle=fopen("$documentroot/order/order.txt",'r+');
if(!$handle) {
echo 'error opening file';
}
$content="pepsi\ncola\npeperoni";
$write=fwrite($handle,$content); //*
if(!$write){ //*
echo 'error writing'; //*
} //*
while(!feof($handle)) {
$string=fgets($handle);
echo $string;
}
你確定PHP賬戶(例如www-data)有寫權限嗎? – Hamish 2010-12-09 06:51:18
您需要在if語句中使用`($ write === false)``。 – 2010-12-09 06:57:17