(15)剪切文件夹
① 通过rename($oldname,$newname) 函数实现剪切文件夹的操作
② 需要检测目标文件夹是否存在,如果存在还要检测目标目录中是否存在同名文件夹,如果不存在则剪切
dir.function.php 添加:
//剪切文件夹 function cutFolder($src,$dst){ if(!file_exists($dst)){ return ‘目标目录不存在‘; }else{ if(!is_dir($dst)){ return ‘不是目录‘; }else{ if(file_exists($dst.‘/‘.basename($src))){ return ‘存在同名文件夹‘; }else{ if(rename($src,$dst.‘/‘.basename($src))){ return ‘剪切成功‘; }else{ return ‘剪切失败‘; } } } } closedir($handle); }
dir.func.php 完整代码:
<?php //遍历目录函数,只读取最外层 function readDirectory($path){ $handle = opendir($path); $arr = array(); while(($item = readdir($handle)) !== false){ //.当前目录和..上级目录 if($item != ‘.‘ && $item != ‘..‘){ if(is_file($path.‘/‘.$item)){ //文件 $arr[‘file‘][] = $item; //把文件保存至二维数组 } if(is_dir($path.‘/‘.$item)){ //目录 $arr[‘dir‘][] = $item; //把目录保存至二维数组 } } } closedir($handle); return $arr; } //得到文件夹大小 function dirSize($path){ $size = 0; $handle = opendir($path); //static $size; global $size; while(($item = readdir($handle)) !== false){ if($item != ‘.‘ && $item != ‘..‘){ if(is_file($path.‘/‘.$item)){ $size += filesize($path.‘/‘.$item); } if(is_dir($path.‘/‘.$item)){ //dirSize($path.‘/‘.$item); //递归的另一种写法 $func = __FUNCTION__; $func($path.‘/‘.$item); } } } closedir($handle); return $size; } //重命名文件夹 function renameFolder($oldname,$newname){ //检测文件夹名称的合法性 if(checkFilename(basename($newname))){ //检测当前目录下是否存在同名文件夹 if(!file_exists($newname)){ if(rename($oldname,$newname)){ $mes = ‘重命名成功‘; }else{ $mes = ‘重命名失败‘; } }else{ $mes = ‘存在同名文件夹‘; } }else{ $mes = ‘非法文件夹名称‘; } return $mes; } //复制文件夹 function copyFolder($src,$dst){ if(!file_exists($dst)){ mkdir($dst,0777,true);//true表示可以创建多级目录 } $handle = opendir($src); while(($item = readdir($handle)) !== false){ if($item != ‘.‘ && $item !== ‘..‘){ if(is_file($src.‘/‘.$item)){ copy($src.‘/‘.$item,$dst.‘/‘.$item); } if(is_dir($src.‘/‘.$item)){ $func = __FUNCTION__; $func($src.‘/‘.$item,$dst.‘/‘.$item); } } } closedir($handle); return ‘复制成功‘; } //剪切文件夹 function cutFolder($src,$dst){ if(!file_exists($dst)){ return ‘目标目录不存在‘; }else{ if(!is_dir($dst)){ return ‘不是目录‘; }else{ if(file_exists($dst.‘/‘.basename($src))){ return ‘存在同名文件夹‘; }else{ if(rename($src,$dst.‘/‘.basename($src))){ return ‘剪切成功‘; }else{ return ‘剪切失败‘; } } } } closedir($handle); }
index.php:
<?php require ‘dir.func.php‘; require ‘file.func.php‘; require ‘common.func.php‘; $path = ‘file‘; $path = @$_REQUEST[‘path‘]?@$_REQUEST[‘path‘]:$path; $info = readDirectory($path); if($info == NULL){ echo ‘<script>alert("没有文件和目录"); </script>‘; } $act = @$_REQUEST[‘act‘]; $filename = @$_REQUEST[‘filename‘]; $dirname = @$_REQUEST[‘dirname‘]; //跳转变量 $redirect = "index.php?path={$path}"; if($act == ‘createFile‘){ //创建文件 $mes = createFile($path.‘/‘.$filename); alertMes($mes,$redirect); }else if($act == ‘showContent‘){ //查看文件内容 $content=file_get_contents($filename); //echo "<textarea readonly=‘readonly‘ cols=‘100‘ rows=‘10‘>{$content}</textarea>"; //高亮显示PHP代码 //高亮显示字符串中的PHP代码 if(strlen($content)){ $newContent=highlight_string($content,true); //高亮显示文件中的PHP代码 //highlight_file($filename); $str=<<<EOF <table width=‘100%‘ bgcolor=‘pink‘ cellpadding=‘5‘ cellspacing="0" > <tr> <td>$newContent</td> </tr> </table> EOF; echo $str; }else{ alertMes("文件没有内容,请编辑再查看!",$redirect); } }else if($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="hidden" name="path" value=‘$path‘> <input type=‘submit‘ value=‘修改文件内容‘> </form> EOF; echo $str; }else if($act == ‘doEdit‘){ //修改文件内容 $content = $_POST[‘content‘]; if(file_put_contents($filename, $content)){ $mes = ‘文件修改成功‘; }else if(!$content){ $mes = ‘文件内容被清空‘; }else{ $mes = ‘文件修改失败‘; } alertMes($mes,$redirect); }else if($act == ‘renameFile‘){ //重命名文件 $str = <<<EOF <form action=‘index.php?act=doRename‘ method=‘post‘> 请填写新文件名:<input type="text" name="newname" placeholder="重命名"> <input type="hidden" name="filename" value=‘$filename‘> <input type="hidden" name="path" value=‘$path‘> <input type=‘submit‘ value=‘重命名‘> </form> EOF; echo $str; }else if($act == ‘doRename‘){ //实现重命名操作 $newname = $_POST[‘newname‘]; $mes = renameFile($filename,$newname); alertMes($mes,$redirect); }else if($act == ‘delFile‘){ $mes = delFile($filename); alertMes($mes,$redirect); }else if($act == ‘downFile‘){ downFile($filename); }else if($act == ‘copyFolder‘){ //复制文件夹 $str = <<<EOF <form action=‘index.php?act=doCopyFolder‘ method=‘post‘> 请将文件夹复制到:<input type="text" name="dstname" placeholder="将文件夹复制到"> <input type="hidden" name="path" value=‘$path‘> <input type="hidden" name="dirname" value=‘$dirname‘> <input type=‘submit‘ value=‘复制文件夹‘> </form> EOF; echo $str; }else if($act == ‘doCopyFolder‘){ $dstname = $_REQUEST[‘dstname‘]; $mes = copyFolder($dirname,$path.‘/‘.$dstname.‘/‘.basename($dirname)); alertMes($mes,$redirect); }else if($act == ‘renameFolder‘){ //重命名文件夹 $str = <<<EOF <form action=‘index.php?act=doRenameFolder‘ method=‘post‘> 请填写新文件夹名:<input type="text" name="newname" placeholder="重命名"> <input type="hidden" name="path" value=‘$path‘> <input type="hidden" name="dirname" value=‘$dirname‘> <input type=‘submit‘ value=‘重命名‘> </form> EOF; echo $str; }else if($act == ‘doRenameFolder‘){ $newname = $_POST[‘newname‘]; //echo $newname,‘-------‘,$dirname,‘-----------‘,$path; $mes = renameFolder($dirname,$path.‘/‘.$newname); alertMes($mes,$redirect); }else if($act == ‘cutFolder‘){ //剪切文件夹 $str = <<<EOF <form action=‘index.php?act=doCutFolder‘ method=‘post‘> 请将文件夹剪切到:<input type="text" name="dstname" placeholder="将文件夹剪切到"> <input type="hidden" name="path" value=‘$path‘> <input type="hidden" name="dirname" value=‘$dirname‘> <input type=‘submit‘ value=‘剪切文件夹‘> </form> EOF; echo $str; }else if($act == ‘doCutFolder‘){ $dstname = $_REQUEST[‘dstname‘]; $mes = cutFolder($dirname,$path.‘/‘.$dstname); alertMes($mes,$redirect); } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link rel="stylesheet" href="cikonss.css" /> <link rel="stylesheet" href="common.css" /> <script src="jquery-1.8.3.min.js"></script> <script src="jquery-ui-1.11.3/jquery-ui.min.js"></script> <link rel="stylesheet" href="jquery-ui-1.11.3/jquery-ui.min.css" /> </head> <body> <div id="showDetail" style="display:none"><img src="" id="showImg"></div> <h1>在线文件管理器</h1> <div id="top"> <ul id="navi"> <li><a href="index.php" title="主目录"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-home"></span></span></a></li> <li><a href="#" onclick="show(‘createFile‘)" title="新建文件" ><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-file"></span></span></a></li> <li><a href="#" title="新建文件夹"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-folder"></span></span></a></li> <li><a href="#" title="上传文件"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-upload"></span></span></a></li> <?php $back = $path ==‘file‘?‘file‘:dirname($path); ?> <li><a href="javascript:void(0)" onclick=‘goBack("<?php echo $back;?>")‘ title="返回上级目录"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-arrowLeft"></span></span></a></li> </ul> </div> <form action="index.php" method="post" enctype="multipart/form-data"> <table width=‘100%‘ border=‘1‘ cellpadding="5" cellspacing="0" bgcolor="#abcdef" align="center"> <tr id="createFolder" style="display:none;"> <td>请输入文件夹名称</td> <td > <input type="text" name="dirname" /> <input type="hidden" name="path" value="<?php echo $path;?>"/> <input type="submit" name="act" value="创建文件夹"/> </td> </tr> <tr id="createFile" style="display:none;"> <td>请输入文件名称</td> <td > <input type="text" name="filename" /> <input type="hidden" name="path" value="<?php echo $path;?>"/> <input type="hidden" name=‘act‘ value=‘createFile‘/> <input type="submit" value="创建文件" /> </td> </tr> <tr id="uploadFile" style="display:none;"> <td >请选择要上传的文件</td> <td ><input type="file" name="myFile" /> <input type="submit" name="act" value="上传文件" /> </td> </tr> <tr align="center"> <td>编号</td> <td>名称</td> <td>类型</td> <td>大小</td> <td>可读</td> <td>可写</td> <td>可执行</td> <td>创建时间</td> <td>修改时间</td> <td>访问时间</td> <td>操作</td> </tr> <?php if(@$info[‘file‘]){ $i = 1; foreach($info[‘file‘] as $val){ $p = $path.‘/‘.$val; ?> <tr align="center"> <td><?php echo $i;?></td> <td><?php echo $val;?></td> <td><?php $src = filetype($p) == ‘file‘?‘file_ico.png‘:‘folder_ico.png‘;?><img src="images/<?php echo $src;?>" title=‘文件‘></td> <td><?php echo transByte(filesize($p));?></td> <td><?php $src = is_readable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可读‘></td> <td><?php $src = is_writeable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可写‘></td> <td><?php $src = is_executable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可写‘></td> <td><?php echo date(‘Y-m-d H:i:s‘,filectime($p));?></td> <td><?php echo date(‘Y-m-d H:i:s‘,filemtime($p));?></td> <td><?php echo date(‘Y-m-d H:i:s‘,fileatime($p));?></td> <td> <?php //得到文件扩展名 $ext = strtolower(end(explode(‘.‘,$val))); $imageExt = array(‘gif‘,‘jpg‘,‘png‘,‘jpeg‘); if(in_array($ext, $imageExt)){ ?> <a href="javascript:void(0)" onclick=‘showDetail("<?php echo $val;?>","<?php echo $p;?>")‘ title=‘查看‘><img src="images/show.png" class="small" ></a> <?php }else{ ?> <a href="index.php?act=showContent&path=<?php echo $path;?>&filename=<?php echo $p;?>" title=‘查看‘><img src="images/show.png" class="small" ></a> <?php } ?> <a href="index.php?act=editContent&path=<?php echo $path;?>&filename=<?php echo $p;?>" title=‘修改‘><img src="images/edit.png" class="small" ></a> <a href="index.php?act=renameFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title=‘重命名‘><img src="images/rename.png" class="small" ></a> <a href="" title=‘复制‘><img src="images/copy.png" class="small" ></a> <a href="" title=‘剪切‘><img src="images/cut.png" class="small" ></a> <a href="javascript:void(0)" onclick="delFile(‘<?php echo $p;?>‘)" title=‘删除‘><img src="images/delete.png" class="small" ></a> <a href="index.php?act=downFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title=‘下载‘><img src="images/download.png" class="small" ></a> </td> </tr> <?php $i++; } } ?> <!--读取目录--> <?php if(@$info[‘dir‘]){ $i = 1; foreach($info[‘dir‘] as $val){ $p = $path.‘/‘.$val; ?> <tr align="center"> <td><?php echo $i;?></td> <td><?php echo $val;?></td> <td><?php $src = filetype($p) == ‘file‘?‘file_ico.png‘:‘folder_ico.png‘;?><img src="images/<?php echo $src;?>" title=‘文件‘></td> <td><?php //$size = 0; echo transByte(dirSize($p));?></td> <td><?php $src = is_readable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可读‘></td> <td><?php $src = is_writeable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可写‘></td> <td><?php $src = is_executable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可写‘></td> <td><?php echo date(‘Y-m-d H:i:s‘,filectime($p));?></td> <td><?php echo date(‘Y-m-d H:i:s‘,filemtime($p));?></td> <td><?php echo date(‘Y-m-d H:i:s‘,fileatime($p));?></td> <td> <a href="index.php?path=<?php echo $p;?>" title=‘查看‘><img src="images/show.png" class="small" ></a> <a href="index.php?act=renameFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title=‘重命名‘><img src="images/rename.png" class="small" ></a> <a href="index.php?act=copyFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title=‘复制‘><img src="images/copy.png" class="small" ></a> <a href="index.php?act=cutFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title=‘剪切‘><img src="images/cut.png" class="small" ></a> <a href="javascript:void(0)" onclick="delFile(‘<?php echo $p;?>‘)" title=‘删除‘><img src="images/delete.png" class="small" ></a> <a href="index.php?act=downFile&filename=<?php echo $p;?>" title=‘下载‘><img src="images/download.png" class="small" ></a> </td> </tr> <?php $i++; } } ?> </table> </form> <script src=‘common.js‘></script> </body> </html>
(16)删除文件夹
没有直接删除非空目录的函数,只能先将目录中的文件通过unlink($filename) 函数删除之后,再将空目录通过rmdir($path) 删除
dir.func.php 中添加:
//删除文件夹 function doDelFolder($path){ $handle = opendir($path); while(($item = readdir($handle)) !== false){ if($item != ‘.‘ && $item != ‘..‘){ if(is_file($path.‘/‘.$item)){ unlink($path.‘/‘.$item); } if(is_dir($path.‘/‘.$item)){ $func = __FUNCTION__; $func($path.‘/‘.$item); } } } closedir($handle); rmdir($path); return ‘删除成功‘; }
dir.func.php 完整代码:
<?php //遍历目录函数,只读取最外层 function readDirectory($path){ $handle = opendir($path); $arr = array(); while(($item = readdir($handle)) !== false){ //.当前目录和..上级目录 if($item != ‘.‘ && $item != ‘..‘){ if(is_file($path.‘/‘.$item)){ //文件 $arr[‘file‘][] = $item; //把文件保存至二维数组 } if(is_dir($path.‘/‘.$item)){ //目录 $arr[‘dir‘][] = $item; //把目录保存至二维数组 } } } closedir($handle); return $arr; } //得到文件夹大小 function dirSize($path){ $size = 0; $handle = opendir($path); //static $size; global $size; while(($item = readdir($handle)) !== false){ if($item != ‘.‘ && $item != ‘..‘){ if(is_file($path.‘/‘.$item)){ $size += filesize($path.‘/‘.$item); } if(is_dir($path.‘/‘.$item)){ //dirSize($path.‘/‘.$item); //递归的另一种写法 $func = __FUNCTION__; $func($path.‘/‘.$item); } } } closedir($handle); return $size; } //重命名文件夹 function renameFolder($oldname,$newname){ //检测文件夹名称的合法性 if(checkFilename(basename($newname))){ //检测当前目录下是否存在同名文件夹 if(!file_exists($newname)){ if(rename($oldname,$newname)){ $mes = ‘重命名成功‘; }else{ $mes = ‘重命名失败‘; } }else{ $mes = ‘存在同名文件夹‘; } }else{ $mes = ‘非法文件夹名称‘; } return $mes; } //复制文件夹 function copyFolder($src,$dst){ if(!file_exists($dst)){ mkdir($dst,0777,true);//true表示可以创建多级目录 } $handle = opendir($src); while(($item = readdir($handle)) !== false){ if($item != ‘.‘ && $item !== ‘..‘){ if(is_file($src.‘/‘.$item)){ copy($src.‘/‘.$item,$dst.‘/‘.$item); } if(is_dir($src.‘/‘.$item)){ $func = __FUNCTION__; $func($src.‘/‘.$item,$dst.‘/‘.$item); } } } closedir($handle); return ‘复制成功‘; } //剪切文件夹 function cutFolder($src,$dst){ if(!file_exists($dst)){ return ‘目标目录不存在‘; }else{ if(!is_dir($dst)){ return ‘不是目录‘; }else{ if(file_exists($dst.‘/‘.basename($src))){ return ‘存在同名文件夹‘; }else{ if(rename($src,$dst.‘/‘.basename($src))){ return ‘剪切成功‘; }else{ return ‘剪切失败‘; } } } } closedir($handle); } //删除文件夹 function doDelFolder($path){ $handle = opendir($path); while(($item = readdir($handle)) !== false){ if($item != ‘.‘ && $item != ‘..‘){ if(is_file($path.‘/‘.$item)){ unlink($path.‘/‘.$item); } if(is_dir($path.‘/‘.$item)){ $func = __FUNCTION__; $func($path.‘/‘.$item); } } } closedir($handle); rmdir($path); return ‘删除成功‘; }
common.func.js 中添加:
//删除文件夹 function delFolder(dirname,path){ if(window.confirm(‘确定要删除文件夹?‘)){ location.href=‘index.php?act=delFolder&dirname=‘+dirname+‘&path=‘+path; } }
common.func.js 完整代码:
//查看文件内容 function show(dis){ document.getElementById(dis).style.display = ‘block‘; } //查看图片 function showDetail(t,filename){ $("#showImg").attr(‘src‘,filename); $("#showDetail").dialog({ height:"auto", width:"auto", position:{my:"center",at:"center",collision:"fit"}, modal:false,//是否模式对话框 draggable:true,//是否允许拖拽 resizable:true,//是否允许缩放 title:t,//对话框标题 show:"slide", hide:"explode" }); } //删除文件 function delFile(filename){ if(window.confirm(‘确定要删除文件?‘)){ location.href=‘index.php?act=delFile&filename=‘+filename; } } //返回上一级目录 function goBack(back){ location.href = "index.php?path="+back; } //删除文件夹 function delFolder(dirname,path){ if(window.confirm(‘确定要删除文件夹?‘)){ location.href=‘index.php?act=delFolder&dirname=‘+dirname+‘&path=‘+path; } }
index.php:
<?php require ‘dir.func.php‘; require ‘file.func.php‘; require ‘common.func.php‘; $path = ‘file‘; $path = @$_REQUEST[‘path‘]?@$_REQUEST[‘path‘]:$path; $info = readDirectory($path); if($info == NULL){ echo ‘<script>alert("没有文件和目录"); </script>‘; } $act = @$_REQUEST[‘act‘]; $filename = @$_REQUEST[‘filename‘]; $dirname = @$_REQUEST[‘dirname‘]; //跳转变量 $redirect = "index.php?path={$path}"; if($act == ‘createFile‘){ //创建文件 $mes = createFile($path.‘/‘.$filename); alertMes($mes,$redirect); }else if($act == ‘showContent‘){ //查看文件内容 $content=file_get_contents($filename); //echo "<textarea readonly=‘readonly‘ cols=‘100‘ rows=‘10‘>{$content}</textarea>"; //高亮显示PHP代码 //高亮显示字符串中的PHP代码 if(strlen($content)){ $newContent=highlight_string($content,true); //高亮显示文件中的PHP代码 //highlight_file($filename); $str=<<<EOF <table width=‘100%‘ bgcolor=‘pink‘ cellpadding=‘5‘ cellspacing="0" > <tr> <td>$newContent</td> </tr> </table> EOF; echo $str; }else{ alertMes("文件没有内容,请编辑再查看!",$redirect); } }else if($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="hidden" name="path" value=‘$path‘> <input type=‘submit‘ value=‘修改文件内容‘> </form> EOF; echo $str; }else if($act == ‘doEdit‘){ //修改文件内容 $content = $_POST[‘content‘]; if(file_put_contents($filename, $content)){ $mes = ‘文件修改成功‘; }else if(!$content){ $mes = ‘文件内容被清空‘; }else{ $mes = ‘文件修改失败‘; } alertMes($mes,$redirect); }else if($act == ‘renameFile‘){ //重命名文件 $str = <<<EOF <form action=‘index.php?act=doRename‘ method=‘post‘> 请填写新文件名:<input type="text" name="newname" placeholder="重命名"> <input type="hidden" name="filename" value=‘$filename‘> <input type="hidden" name="path" value=‘$path‘> <input type=‘submit‘ value=‘重命名‘> </form> EOF; echo $str; }else if($act == ‘doRename‘){ //实现重命名操作 $newname = $_POST[‘newname‘]; $mes = renameFile($filename,$newname); alertMes($mes,$redirect); }else if($act == ‘delFile‘){ $mes = delFile($filename); alertMes($mes,$redirect); }else if($act == ‘downFile‘){ downFile($filename); }else if($act == ‘copyFolder‘){ //复制文件夹 $str = <<<EOF <form action=‘index.php?act=doCopyFolder‘ method=‘post‘> 请将文件夹复制到:<input type="text" name="dstname" placeholder="将文件夹复制到"> <input type="hidden" name="path" value=‘$path‘> <input type="hidden" name="dirname" value=‘$dirname‘> <input type=‘submit‘ value=‘复制文件夹‘> </form> EOF; echo $str; }else if($act == ‘doCopyFolder‘){ $dstname = $_REQUEST[‘dstname‘]; $mes = copyFolder($dirname,$path.‘/‘.$dstname.‘/‘.basename($dirname)); alertMes($mes,$redirect); }else if($act == ‘renameFolder‘){ //重命名文件夹 $str = <<<EOF <form action=‘index.php?act=doRenameFolder‘ method=‘post‘> 请填写新文件夹名:<input type="text" name="newname" placeholder="重命名"> <input type="hidden" name="path" value=‘$path‘> <input type="hidden" name="dirname" value=‘$dirname‘> <input type=‘submit‘ value=‘重命名‘> </form> EOF; echo $str; }else if($act == ‘doRenameFolder‘){ $newname = $_POST[‘newname‘]; //echo $newname,‘-------‘,$dirname,‘-----------‘,$path; $mes = renameFolder($dirname,$path.‘/‘.$newname); alertMes($mes,$redirect); }else if($act == ‘cutFolder‘){ //剪切文件夹 $str = <<<EOF <form action=‘index.php?act=doCutFolder‘ method=‘post‘> 请将文件夹剪切到:<input type="text" name="dstname" placeholder="将文件夹剪切到"> <input type="hidden" name="path" value=‘$path‘> <input type="hidden" name="dirname" value=‘$dirname‘> <input type=‘submit‘ value=‘剪切文件夹‘> </form> EOF; echo $str; }else if($act == ‘doCutFolder‘){ $dstname = $_REQUEST[‘dstname‘]; $mes = cutFolder($dirname,$path.‘/‘.$dstname); alertMes($mes,$redirect); }else if($act == ‘delFolder‘){ //删除文件夹 $mes = doDelFolder($dirname); alertMes($mes,$redirect); } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link rel="stylesheet" href="cikonss.css" /> <link rel="stylesheet" href="common.css" /> <script src="jquery-1.8.3.min.js"></script> <script src="jquery-ui-1.11.3/jquery-ui.min.js"></script> <link rel="stylesheet" href="jquery-ui-1.11.3/jquery-ui.min.css" /> </head> <body> <div id="showDetail" style="display:none"><img src="" id="showImg"></div> <h1>在线文件管理器</h1> <div id="top"> <ul id="navi"> <li><a href="index.php" title="主目录"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-home"></span></span></a></li> <li><a href="#" onclick="show(‘createFile‘)" title="新建文件" ><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-file"></span></span></a></li> <li><a href="#" title="新建文件夹"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-folder"></span></span></a></li> <li><a href="#" title="上传文件"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-upload"></span></span></a></li> <?php $back = $path ==‘file‘?‘file‘:dirname($path); ?> <li><a href="javascript:void(0)" onclick=‘goBack("<?php echo $back;?>")‘ title="返回上级目录"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-arrowLeft"></span></span></a></li> </ul> </div> <form action="index.php" method="post" enctype="multipart/form-data"> <table width=‘100%‘ border=‘1‘ cellpadding="5" cellspacing="0" bgcolor="#abcdef" align="center"> <tr id="createFolder" style="display:none;"> <td>请输入文件夹名称</td> <td > <input type="text" name="dirname" /> <input type="hidden" name="path" value="<?php echo $path;?>"/> <input type="submit" name="act" value="创建文件夹"/> </td> </tr> <tr id="createFile" style="display:none;"> <td>请输入文件名称</td> <td > <input type="text" name="filename" /> <input type="hidden" name="path" value="<?php echo $path;?>"/> <input type="hidden" name=‘act‘ value=‘createFile‘/> <input type="submit" value="创建文件" /> </td> </tr> <tr id="uploadFile" style="display:none;"> <td >请选择要上传的文件</td> <td ><input type="file" name="myFile" /> <input type="submit" name="act" value="上传文件" /> </td> </tr> <tr align="center"> <td>编号</td> <td>名称</td> <td>类型</td> <td>大小</td> <td>可读</td> <td>可写</td> <td>可执行</td> <td>创建时间</td> <td>修改时间</td> <td>访问时间</td> <td>操作</td> </tr> <?php if(@$info[‘file‘]){ $i = 1; foreach($info[‘file‘] as $val){ $p = $path.‘/‘.$val; ?> <tr align="center"> <td><?php echo $i;?></td> <td><?php echo $val;?></td> <td><?php $src = filetype($p) == ‘file‘?‘file_ico.png‘:‘folder_ico.png‘;?><img src="images/<?php echo $src;?>" title=‘文件‘></td> <td><?php echo transByte(filesize($p));?></td> <td><?php $src = is_readable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可读‘></td> <td><?php $src = is_writeable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可写‘></td> <td><?php $src = is_executable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可写‘></td> <td><?php echo date(‘Y-m-d H:i:s‘,filectime($p));?></td> <td><?php echo date(‘Y-m-d H:i:s‘,filemtime($p));?></td> <td><?php echo date(‘Y-m-d H:i:s‘,fileatime($p));?></td> <td> <?php //得到文件扩展名 $ext = strtolower(end(explode(‘.‘,$val))); $imageExt = array(‘gif‘,‘jpg‘,‘png‘,‘jpeg‘); if(in_array($ext, $imageExt)){ ?> <a href="javascript:void(0)" onclick=‘showDetail("<?php echo $val;?>","<?php echo $p;?>")‘ title=‘查看‘><img src="images/show.png" class="small" ></a> <?php }else{ ?> <a href="index.php?act=showContent&path=<?php echo $path;?>&filename=<?php echo $p;?>" title=‘查看‘><img src="images/show.png" class="small" ></a> <?php } ?> <a href="index.php?act=editContent&path=<?php echo $path;?>&filename=<?php echo $p;?>" title=‘修改‘><img src="images/edit.png" class="small" ></a> <a href="index.php?act=renameFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title=‘重命名‘><img src="images/rename.png" class="small" ></a> <a href="" title=‘复制‘><img src="images/copy.png" class="small" ></a> <a href="" title=‘剪切‘><img src="images/cut.png" class="small" ></a> <a href="javascript:void(0)" onclick="delFile(‘<?php echo $p;?>‘)" title=‘删除‘><img src="images/delete.png" class="small" ></a> <a href="index.php?act=downFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title=‘下载‘><img src="images/download.png" class="small" ></a> </td> </tr> <?php $i++; } } ?> <!--读取目录--> <?php if(@$info[‘dir‘]){ $i = 1; foreach($info[‘dir‘] as $val){ $p = $path.‘/‘.$val; ?> <tr align="center"> <td><?php echo $i;?></td> <td><?php echo $val;?></td> <td><?php $src = filetype($p) == ‘file‘?‘file_ico.png‘:‘folder_ico.png‘;?><img src="images/<?php echo $src;?>" title=‘文件‘></td> <td><?php //$size = 0; echo transByte(dirSize($p));?></td> <td><?php $src = is_readable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可读‘></td> <td><?php $src = is_writeable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可写‘></td> <td><?php $src = is_executable($p)?‘correct.png‘:‘error.png‘;?><img src="images/<?php echo $src;?>" class="small" title=‘可写‘></td> <td><?php echo date(‘Y-m-d H:i:s‘,filectime($p));?></td> <td><?php echo date(‘Y-m-d H:i:s‘,filemtime($p));?></td> <td><?php echo date(‘Y-m-d H:i:s‘,fileatime($p));?></td> <td> <a href="index.php?path=<?php echo $p;?>" title=‘查看‘><img src="images/show.png" class="small" ></a> <a href="index.php?act=renameFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title=‘重命名‘><img src="images/rename.png" class="small" ></a> <a href="index.php?act=copyFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title=‘复制‘><img src="images/copy.png" class="small" ></a> <a href="index.php?act=cutFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title=‘剪切‘><img src="images/cut.png" class="small" ></a> <a href="javascript:void(0)" onclick="delFolder(‘<?php echo $p;?>‘,‘<?php echo $path;?>‘)" title=‘删除‘><img src="images/delete.png" class="small" ></a> <a href="index.php?act=downFile&filename=<?php echo $p;?>" title=‘下载‘><img src="images/download.png" class="small" ></a> </td> </tr> <?php $i++; } } ?> </table> </form> <script src=‘common.js‘></script> </body> </html>
Web 在线文件管理器学习笔记与总结(15)剪切文件夹 (16)删除文件夹
原文:http://www.cnblogs.com/dee0912/p/4395944.html