Home  >  Article  >  Backend Development  >  How to implement editing and saving files in php

How to implement editing and saving files in php

WBOY
WBOYOriginal
2016-07-25 08:44:35961browse

The example in this article describes how to edit and save files in PHP. Share it with everyone for your reference. The details are as follows:

save_file.php:

  1. session_start();
  2. $handle = fopen($_POST['original_file_name'], "w");
  3. $text = $_POST['file_contents'];
  4. if(fwrite( $handle, $text) == FALSE){
  5. $_SESSION['error'] = 'There was an error';
  6. }else{
  7. $_SESSION[' error'] = 'File edited successfully';
  8. }
  9. fclose($handle);
  10. header("Location: ".$_POST['page']);
  11. ?>
Copy code

read_file.php:

  1. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
  2. Untitled Document
Copy code

I hope this article will be helpful to everyone’s PHP programming design.

Save file, php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn