PHP Developer Channel :: 討論園地

您尚未登入。

#1 2005-04-20 10:40:00

profitssor
New member
註冊日期: 2005-04-20
文章數: 2

如何用php寫一版給使用者留下個人資料的頁面?而又...

如何用php寫一版給使用者留下個人資料的簡單頁面?
而又不用任何database 儲存, 只用 一個 plain text file 儲起?

請指教!謝謝!!

離線

 

#2 2005-05-13 09:07:55

ruby
Member
註冊日期: 2005-05-10
文章數: 30

Re: 如何用php寫一版給使用者留下個人資料的頁面?而又...

<?php
$filename = 'test.txt';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
   
   echo "Success, wrote ($somecontent) to file ($filename)";
   
   fclose($handle);

} else {
   echo "The file $filename is not writable";
}
?>

離線

 

論壇頁尾

Web Hosting
PHP Developer Channel
Powered by PunBB 1.2.9
© Copyright 2002–2005 Rickard Andersson