編輯完成後,提交內容時,需要把原來的文件路徑也提交,
然後服務端直接file_put_contents(文件名,文件內容,true); 就可以了。

解决方案 »

  1.   

    http://www.example.com/index.php?file=1.html然後在同目錄下創建一個1.html
    index.php<?php
    $file = isset($_REQUEST['file'])? $_REQUEST['file'] : '';if($file=='' || file_exists($file)==false){
    echo 'file not exists';
    exit();
    }$content = isset($_POST['content'])? $_POST['content'] : '';if($content!=''){ // 有修改
    file_put_contents($file, $content, true);
    }?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
     <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <title> New Document </title>
     </head> <body>
      <form name="form1" action="" method="post">
      <p>文件內容</p>
      <p><textarea name="content" style="width:500px;height:300px;"><?php echo file_get_contents($file); ?></textarea></p>
      <p><input type="submit" name="b1" value="修改"></p>
      </form>
     </body>
    </html>