[英]Trouble with writing to file with php and my home server
所以,我有這個簡單的小php腳本。 它可以正常運行和編譯,並且可以在我編碼的機器上以我想要的方式工作。 我正在運行32位Debian 6.0.6的個人家庭Web服務器上運行它。 它是用apache編寫的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.
?>
通過網絡瀏覽器從服務器訪問文件時,顯示“無法寫入文件”。 錯誤。 因此,它將正確打開文件並進行讀取。 當打開它進行寫入時,它將失敗。 我假設這是某種權限問題。 我對如何解決這個問題有些困惑。 有任何想法嗎? 協助將不勝感激! 我已經在Google上搜索了幾天,但無法解決該問題。 我是php'noob',對於運行基於linux的網絡服務器非常陌生,但是,您必須以某種方式學習。 :* l
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.