文件修改失败
error_reporting(E_ALL || ~E_NOTICE);
require_once 'dir.func.php';
require_once 'file.func.php';
require_once 'common.func.php';
$path = "file";
$info = readDirectory($path);
$act = $_REQUEST['act'];
$filename = $_REQUEST['filename'];
$redirect = "index.php?path={$path}";
if($act == "createFile"){
//创建文件
$mes = createFile($path."/".$filename);
alertMes($mes,$redirect);
}elseif($act == "showContent"){
//查看文件内容
$content = file_get_contents($filename);
if(strlen($content)==0)
{
alertMes("文件为空,请编辑后查看!", $redirect);
}else{
echo "<textarea readonly='readonle' cols='100' rows='10'>{$content}</textarea>";
}
}elseif($act == "editContent"){
//修改操作
$content = file_get_contents($filename);
$str = <<<EOF
<form action="index.php?act=doEdit" method="post">
<textarea name="content" cols='100' rows='10'>{$content}</textarea>
<br/>
<input type="hidden" name="filename" value={$filename}/>
<input type="submit" value="确认修改"/>
</form>
EOF;
echo $str;
}elseif($act == "doEdit"){
$content = $_POST['content'];
echo $fileaname;//这里输出的是file/1.txt/ 莫名其妙的多了一个/,但是其他地方输出文件名字的话就不会有这个/
if(file_put_contents($filename, $content)){
alertMes("文件已修改成功!", $redirect);
}else{
alertMes("文件修改失败!", $redirect);
}
}