thatsnotmynameqq飞车:if ($_GET['action'] == "editfile"){

来源:百度文库 编辑:高校问答 时间:2024/04/28 11:51:50
if ($_GET['action'] == "editfile"){
$filename="$dir/$editfile";
$fp=@fopen($filename,"r");
$contents=@fread($fp, filesize($filename));
$contents=htmlspecialchars($contents);
echo "<p><hr width=\"775\" align=\"left\"><font color=red>如果该文件不存在,将创建这个文件名的文件!</font>";
echo '<form action=\"?savefile&dir=".rawurlencode($dir)."&savefile=".rawurlencode($file)."\" method=\"post\">';
echo "<textarea cols=\"100\" rows=\"20\" name=\"contents\">";
echo "$contents";
echo "</textarea><br>";
echo "<input type=\"submit\" value=\"确定保存\">";
echo "</form><hr width=\"775\" align=\"left\">";
@fclose($fp);
}
//保存文件
if ($_POST['do'] == 'savefile') {
if (!empty($_POST['editfilename'])) {
$filename="$editfilename";
@$fp=fopen("$filename","w");
if($_POST['change']=="yes"){
// $filecontent = "?".">".$_POST['contents']."<?";
$filecontent = htmlspecialchars($contents);
$filecontent = gzdeflate($filecontent);
}else{
$filecontent = $_POST['contents'];
}
echo $msg=@fwrite($fp,$filecontent) ? "写入文件成功!" : "写入失败!";
@fclose($fp);
}
else {
echo "您想编辑的文件好像不存在!或者内容没写!!";
}
}