满洲里森晟网络工作室
设为首页
收藏本站
24小时服务热线:13274708577     
 
  网站位置:首页 >> 网页编程
php如何实现编辑和保存文件
作者:admin 发表时间:2015/8/9 人气:
 

本文实例讲述了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 class="redtxt">There was an error</span>';
}else{
$_SESSION['error'] = '<span class="redtxt">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 name="file_contents" style="width:700px;height:600px;">
<?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; ?> " name="original_file_name" />
</form>
<body>
</body>
</html>





文章来源:www.sensheng.net.cn
文章点评
  
新闻资讯建站常识
网络安全网页编程
电脑技术摄影美文
知识百科相关下载
问题解答帮助中心
Window2008+IIS7出现错...
Window2008+IIS7部署网...
如何清除“远程桌面连...
win7删除文件夹提示找...
WIN7远程桌面窗口的字...
三星笔记本WIN8系统改...
防止信用卡泄密的四个...
WindowsInstaller服务...
WIN8.1开机弹出syslev...
草原人包车旅游网  满洲里森晟网络工作室  新远货运代理有限公司  满洲里中润宏源进出口  满洲里中欧门业  百度搜索  360搜索  
 
 
Copyright © 2006—2023 www.SenSheng.net.cn  All Rights Reserved.  满洲里森晟网络工作室