php实现编辑和保存文件的方法

save_file.php

<?php session_start(); $handle = fopen($_POST['original_file_name'], "w"); $text = $_POST['file_contents']; if(fwrite($handle, $text) == FALSE){ $_SESSION['error'] = '<span>There was an error</span>'; }else{ $_SESSION['error'] = '<span>File edited successfully</span>'; } fclose($handle); header("Location: ".$_POST['page']); ?>

read_file.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <form action="savecontents.php" method="post"> <textarea> <?php $fileName = "location/of/orignal/file/my_file.php"; $handle = fopen($fileName, "r"); while (!feof($handle)){ $text = fgets($handle); echo $text; } ?> </textarea> <input type="hidden" value=" <? echo $fileName; ?> " /> </form> <body> </body> </html>

希望本文所述对大家的php程序设计有所帮助。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/e964ffaab22818e4af8735a3ff881552.html