2012-03-17 40 views
0

我得到一個頁面的源代碼如下:如何在php中寫入文件?

<? $txt = file_get_contents('http://stats.pingdom.com/file'); 
echo $txt; ?> 

並打印在屏幕上,但說實話其實我是想取代其現有的HTML文件中的每個1分鐘。 (我將每1分鐘打開一次文件)

我該怎麼做?

+0

爲什麼你甚至需要一個PHP腳本來做到這一點?您是否嘗試過使用'wget http://stats.pingdom.com/file -o/path/to/the/file/locally',並將其添加到您的crontab */1 * * * *'中以便每分鐘運行一次? – 2012-03-17 19:24:00

回答

1

如果你已經學會了使用的file_get_contents()再考慮他的妹妹功能file_put_contents()

$txt = file_get_contents('http://stats.pingdom.com/file'); 
file_put_contents('/path/to/my/file.html',$txt); 

要運行它的每一分鐘,看東西比如cron(或等值您選擇的操作平臺上)

+0

謝謝,這需要一個絕對路徑? – Chriswede 2012-03-17 19:47:42

+0

,因爲我得到這個:Warning:file_put_contents(/home/xyz/public_html/stats/stats.html)[function.file-put-contents]:未能打開流:權限在/ home/xyz/public_html/index中被拒絕第3行的.php – Chriswede 2012-03-17 19:50:49

+0

文件夾統計信息是777 – Chriswede 2012-03-17 19:53:16