代码那错了啊?
输出错误如下Warning: rename(./新建文本文档11.txt,./新建文本文档111.txt) [function.rename]: Permission denied in H:\www\20111023\6.php on line 69
<?php/**
* @author phpadmin
* @copyright 2011
*///=====================文件读取浏览操作=============
//获取当前目录
$dir=".";
//打开目录
$filedir=opendir($dir);
//制作表格
echo "<center><table width='800' border='1'>
<tr>
<th>编号</th><th>文件名</th><th>大小</th><th>文件属性</th><th>文件操作</th>
</tr>";
//遍历目录读取
$i=0;while($file=readdir($filedir)){
if($file!="." && $file!=".."){
echo "<tr>";
echo "<td>{$i}</td>";
echo "<td>{$file}</td>";
//文件大小
echo "<td>".filesize($file)."</td>";
//判断是文件还是目录
echo "<td>".(filetype($file)=="dir"?"目录":"文件")."</td>";
//文件操作
//<a href=\"6.php?dir=1\">修改</a> <a href=\"6.php?dir=2\">删除</a> <a href=\"6.php?dir=3\">移动</a> <a href=\"6.php?dir=4\">复制</a>
echo "<td>".((!is_dir($file))?"<a href=\"6.php?dir=1&name={$file}\">编辑</a> <a href=\"6.php?dir=2&name={$file}\">删除</a> <a href=\"6.php?dir=3&name={$file}\">移动</a> <a href=\"6.php?dir=4&name={$file}\">复制</a> ":"<a href=\"6.php?dir=5&name={$file}\">重命名</a> <a href=\"6.php?dir=2&name={$file}\">删除</a> <a href=\"6.php?dir=3&name={$file}\">移动</a> <a href=\"6.php?dir=4&name={$file}\">复制</a> ")."</td>";
echo "</tr>";
$i++;
}
}
echo "</center></table>";
//====================文件动作=====================
switch($_GET["dir"]){
case 1;//修改动作
$ff = rtrim($dir,"/")."/".($_GET['name']);
$dd = fopen($ff,"r+");
$d = fread($dd,1024);
echo "<form cation='6.php' method='post'>";
echo "<h3>编辑内容</h3>";
echo "文件名可重命名<br/>文件名:<input type='text' name='newfile' value=\"{$_GET['name']}\"><br/>";
echo "<input type='hidden' name='hid' value='{$_GET['name']}'>";
echo "<input type='hidden' name='edit' value='1'>";
echo "<textarea name='newedit' rows='5' cols='10'>{$d}</textarea><br/>";
echo "<input type='submit' value='提交'>";
echo "</form>";
break;
}
//==============================判断文件数据====================
if($_POST['edit']==1){
if(!is_null($_POST['newedit']) && !is_null($_POST['newfile'] )){
//判断有没有修改文件名
//考虑修改了文件名字的
if($_POST['newfile']!=$_POST['hid']){
//旧的文件名
$old=$_POST['hid'];
$oldf=rtrim($dir,"/")."/".$old;
//新文件路径
$newf=rtrim($dir,"/")."/".$_POST['newfile'];
//重新命名文件名
rename($oldf,$newf);
//重新创建文件写入内容
$wf=fopen($newf,"w");
fwrite($wf,$_POST['newedit']);
}else{
//旧的文件名
$oldf=rtrim($dir,"/")."/".$_POST['hid'];
$wf=fopen($oldf,"w");
fwrite($wf,$_POST['newedit']);
}
}
}
//删除目录函数
function sc($sc){
//判断是否是文件
$file=opendir($sc);
//读取目录中所有文件
while($delfile=readdir($file)){
//排除。跟。。目录
if($delfile!="." && $delfile!=".."){
//组成文件路径形式
$delfileile=$sc."/".$delfile;
if(is_file($delfileile)){
//发现文件则删除
unlink($delfileile);
}else{
//发现目录,则调用函数
sc($delfileile);
}
}
}
closedir($file);
if(rmdir($sc)){
return true;
}else{
return false;
}
}
?>
输出错误如下Warning: rename(./新建文本文档11.txt,./新建文本文档111.txt) [function.rename]: Permission denied in H:\www\20111023\6.php on line 69
<?php/**
* @author phpadmin
* @copyright 2011
*///=====================文件读取浏览操作=============
//获取当前目录
$dir=".";
//打开目录
$filedir=opendir($dir);
//制作表格
echo "<center><table width='800' border='1'>
<tr>
<th>编号</th><th>文件名</th><th>大小</th><th>文件属性</th><th>文件操作</th>
</tr>";
//遍历目录读取
$i=0;while($file=readdir($filedir)){
if($file!="." && $file!=".."){
echo "<tr>";
echo "<td>{$i}</td>";
echo "<td>{$file}</td>";
//文件大小
echo "<td>".filesize($file)."</td>";
//判断是文件还是目录
echo "<td>".(filetype($file)=="dir"?"目录":"文件")."</td>";
//文件操作
//<a href=\"6.php?dir=1\">修改</a> <a href=\"6.php?dir=2\">删除</a> <a href=\"6.php?dir=3\">移动</a> <a href=\"6.php?dir=4\">复制</a>
echo "<td>".((!is_dir($file))?"<a href=\"6.php?dir=1&name={$file}\">编辑</a> <a href=\"6.php?dir=2&name={$file}\">删除</a> <a href=\"6.php?dir=3&name={$file}\">移动</a> <a href=\"6.php?dir=4&name={$file}\">复制</a> ":"<a href=\"6.php?dir=5&name={$file}\">重命名</a> <a href=\"6.php?dir=2&name={$file}\">删除</a> <a href=\"6.php?dir=3&name={$file}\">移动</a> <a href=\"6.php?dir=4&name={$file}\">复制</a> ")."</td>";
echo "</tr>";
$i++;
}
}
echo "</center></table>";
//====================文件动作=====================
switch($_GET["dir"]){
case 1;//修改动作
$ff = rtrim($dir,"/")."/".($_GET['name']);
$dd = fopen($ff,"r+");
$d = fread($dd,1024);
echo "<form cation='6.php' method='post'>";
echo "<h3>编辑内容</h3>";
echo "文件名可重命名<br/>文件名:<input type='text' name='newfile' value=\"{$_GET['name']}\"><br/>";
echo "<input type='hidden' name='hid' value='{$_GET['name']}'>";
echo "<input type='hidden' name='edit' value='1'>";
echo "<textarea name='newedit' rows='5' cols='10'>{$d}</textarea><br/>";
echo "<input type='submit' value='提交'>";
echo "</form>";
break;
}
//==============================判断文件数据====================
if($_POST['edit']==1){
if(!is_null($_POST['newedit']) && !is_null($_POST['newfile'] )){
//判断有没有修改文件名
//考虑修改了文件名字的
if($_POST['newfile']!=$_POST['hid']){
//旧的文件名
$old=$_POST['hid'];
$oldf=rtrim($dir,"/")."/".$old;
//新文件路径
$newf=rtrim($dir,"/")."/".$_POST['newfile'];
//重新命名文件名
rename($oldf,$newf);
//重新创建文件写入内容
$wf=fopen($newf,"w");
fwrite($wf,$_POST['newedit']);
}else{
//旧的文件名
$oldf=rtrim($dir,"/")."/".$_POST['hid'];
$wf=fopen($oldf,"w");
fwrite($wf,$_POST['newedit']);
}
}
}
//删除目录函数
function sc($sc){
//判断是否是文件
$file=opendir($sc);
//读取目录中所有文件
while($delfile=readdir($file)){
//排除。跟。。目录
if($delfile!="." && $delfile!=".."){
//组成文件路径形式
$delfileile=$sc."/".$delfile;
if(is_file($delfileile)){
//发现文件则删除
unlink($delfileile);
}else{
//发现目录,则调用函数
sc($delfileile);
}
}
}
closedir($file);
if(rmdir($sc)){
return true;
}else{
return false;
}
}
?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货