所以,我有這個簡單的小php腳本。它運行並編譯得很好,並按照我希望它在我編碼的機器上工作的方式工作。我在運行Debian 6.0.6,32位的個人家庭網絡服務器上運行它。這是Apache的PHP。而且我知道一個事實,即PHP正在服務器上工作。與php和我的家庭服務器寫入文件的麻煩
<?php
$hitsfile = "hits.txt"; #name of file
$filehandle = fopen($hitsfile, 'r') or die ("Couldn't read file."); #Opens file, 'hitsfile' to be read.
$hits = fread($filehandle, 5); #reads file to the introduced variable, 'hits'
fclose($filehandle); #closes file
$hits++; #increments the variable that it read.
$filehandle = fopen($hitsfile, 'w') or die ("Couldn't write to file."); #opens file to be read.
fwrite($filehandle, $hits); #writes the hits variable to file.
fclose($filehandle); #closes file.
echo $hits; #outputs the hits variable.
?>
當我通過網絡瀏覽器從服務器訪問文件時,出現「無法寫入文件」。錯誤。那麼,它正確地打開文件,並閱讀它。當它打開它寫入時,它會失敗。我假設這是一些權限問題或其他問題。我對如何解決這個問題感到不知所措。有任何想法嗎?援助將不勝感激!我已經搜索了幾天,我無法解決這個問題。我是一個php'noob',我對運行一個基於linux的web服務器很陌生,但是,嘿,你必須學習。 :* l
確保文件權限允許寫入文件並且它不是隻讀的。 – SISYN
'var_dump(is_writable($ hitsfile));'告訴你什麼? – Niko