溫瑞烘老師的教學歷程檔案(Teaching ePortfolio) - 100-2四技資管二甲乙網頁程式設計 - 第十三週 檔案上傳
 

資訊管理系
副教授
温瑞烘


歷程檔案 Portfolio


關於我 About Me

第十三週 檔案上傳

<?php
   // 檔案操作
   $fp=fopen("test.txt","w");        // 開啟檔案 寫入
   for ($i=1; $i<=100; $i++) {   
     fputs($fp,$i);                          // 寫入檔案
     fputs($fp,"\n");                       // 跳列
   }
   fclose($fp);                              // 關檔
   $fp=fopen("test.txt","r");       // 開檔  輸入
   while ($line=fgets($fp))  {    // 讀入檔案,每次一列
     echo $line;                           // 顯示於瀏覽器
     echo "<br>";                        // 跳列
   };
   fclose($fp);                            // 關檔
?>


 <?php
 // 留言板
  $command=$_POST["command"];
  if ($command==null || $command=="返回")  {
   echo("<html><body><center>
    <form method=post action=$SELF_PHP>
     留言版: <p>
     <textarea name='note' rows=3 cols=40 wrap=physical></textarea><p>
     <input type=submit name=command value=留言>
     <input type=submit name=command value=存檔>
     <input type=submit name=command value=讀取>
     <input type=submit name=command value=關閉>
     <input type=reset  name=command value=清除>
     </form></center></body></html>");
  }
  if ($command=="關閉") die();
  if ($command=="留言") {
    $note=$_POST["note"];
    $note = str_replace("\n", "<br>", $note);
    echo("<center>留言: <p>$note</center>");
    echo("<form method=post action=$SELF_PHP>
          <input type=submit name=command value=返回>
          <input type=submit name=command value=關閉>
          </form>");
  }
  if ($command=="存檔") {
    $note=$_POST["note"];
    $fp=fopen("test.txt","w");        // 開啟檔案 寫入
    fputs($fp,$note);                 // 寫入檔案
    fclose($fp);
    echo("存檔完成
          <form method=post action=$SELF_PHP>
          <input type=submit name=command value=返回>
          <input type=submit name=command value=關閉>
          </form>");
  }
  if ($command=="讀取") {
    $fp=fopen("test.txt","r");        // 開啟檔案 寫入
    while ($line=fgets($fp))  {    // 讀入檔案,每次一列
     $note=$note.$line;                           // 顯示於瀏覽器
    };
    echo("<html><body><center>讀取完成
          <form method=post action=$SELF_PHP>
          留言版: <p>
          <textarea name='note' rows=3 cols=40 wrap=physical>$note</textarea><p>
          <input type=submit name=command value=留言>
          <input type=submit name=command value=存檔>
          <input type=submit name=command value=讀取>
          <input type=reset  name=command value=清除>
          </form></center></body></html>");
  }
?>











 

全部共 0則留言
登入帳號密碼代表遵守學術網路規範
 


文章分類 Labels

 


最新文章 Top10

中華科技大學數位化學習歷程 - 意見反應