本文实例讲述了php实现编辑和保存文件的方法。分享给大家供大家参考。具体如下:
save_file.php:
-
- session_start();
- $handle = fopen($_POST['original_file_name'], "w");
- $text = $_POST['file_contents'];
- if(fwrite($handle, $text) == FALSE){
- $_SESSION['error'] = 'There was an error';
- }else{
- $_SESSION['error'] = 'File edited successfully';
- }
- fclose($handle);
- header("Location: ".$_POST['page']);
- ?>
-
-
复制代码
read_file.php:
-
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- Untitled Document
- $fileName = "location/of/orignal/file/my_file.php";
- $handle = fopen($fileName, "r");
- while (!feof($handle)){
- $text = fgets($handle);
- echo $text;
- }
- ?>
-
-
复制代码
希望本文所述对大家的php程序设计有所帮助。
|