本篇文章主要介绍php针对文件的读取、编辑和保存的操作,感兴趣的朋友参考下,希望对大家有所帮助。
本文实例讲述了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'] = 'There was an error';
}else{
$_SESSION['error'] = 'File edited successfully';
}
fclose($handle);
header("Location: ".$_POST['page']);
?>
read_file.php:
Untitled Document$fileName = "location/of/orignal/file/my_file.php";
$handle = fopen($fileName, "r");
while (!feof($handle)){
$text = fgets($handle);
echo $text;
}
?>
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐: