rename()对文件夹操作引发了SFTP出问题,
跟King老师一步步做,学到了很多东西,但我对linux是菜鸟,不知是哪里出问题了,百度了两天了,也没能查了问题。
rename()删除或重命名文件夹,点击后,ubuntu要反应很长时间,才能响应,操作的确成功了,但我的Sftp随之也坏掉不能上传文件了,上传操作只上传个文件名,零字节,报unknow error
求King老师指点!!!
<?php
require_once 'inc/common.func.php';
$act=$_REQUEST['act'];
$dst=$_REQUEST['dst'];
$ori=$_REQUEST['ori'];
$path='file';
$path=$_REQUEST['path']?$_REQUEST['path']:$path;
$redirect="?path={$path}";
//$filename=$_REQUEST['filename'];
//$newname=$_REQUEST['newname'];
//$dirname=$_REQUEST['dirname'];
$back=($path=="file")?"file":dirname($path);
$info=readDirectory($path);
//print_r($info);
//if(!$info){
// echo "<Script>alert('没有文件或目录');location.href='?'<//script>" ;
//};
if($act=='createFile'){//创建文件
$mes=createFile($path."/".$dst);
alertMes($mes,$redirect);
}elseif($act=='editContent'){//修改文件 内容的操作
$mes=editContent($path.'/'.$ori,$dst);
alertMes($mes,$redirect);
}elseif($act=="renameFile"){//实现重命名操作
//echo $ori.'-----'.$dst;
$mes=renameFile($ori,$dst);
alertMes($mes,$redirect);
}elseif($act=="delFile"){//删除文件
$mes=delfile($ori);
alertMes($mes,$redirect);
}elseif($act=="downFile"){//下载文件
$mes=downFile($filename);
// alertMes($mes,$redirect);
}elseif($act=="createFolder"){//创建文件夹
// echo $path."----".$dirname;
$mes=createFolder($path,$dst);
alertMes($mes,$redirect);
}elseif($act=="renameFolder"){
// echo $newname,"----",$dirname,"------",$path;
$mes=renameFolder($ori,$path.'/'.$dst);
alertMes($mes,$redirect);
}elseif($act=="copyFolder"){
// echo $ori,'----',$path."/".$dst."/".basename($ori);
$mes=copyFolder($ori,$path."/".$dst."/".basename($ori));
alertMes($mes,$redirect);
}elseif($act=="cutFolder"){
// echo $ori,'----',$path."/".$dst."/".basename($ori);
$mes=cutFolder($ori,$path."/".$dst."/".basename($ori));
alertMes($mes,$redirect);
}elseif($act=="copyFile"){
$mes=copyFile($ori,$path."/".$dst."/".basename($ori));
alertMes($mes,$redirect);
}elseif($act=="cutFile"){
$mes=cutFile($ori,$path."/".$dst."/".basename($ori));
alertMes($mes,$redirect);
}elseif($act=="delFolder"){
// echo $ori;
$mes=delFolder($ori);
alertMes($mes,$redirect);
}elseif($act=="uploadFile"){
// print_r($_FILES);
$fileInfo=$_FILES['dst'];
$mes=uploadFile($fileInfo,$path);
alertMes($mes,$redirect);
}
?>
<!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=utf-8" />
<title>filelist</title>
<link rel="stylesheet" href="inc/jquery-ui.css" />
<style type="text/css">
body,p,div,ul,ol,table{ magin:0; padding:0; }
#fitop span,.Opt span{cursor:pointer}
.TTh td{background-color:#ABCDEF;border-bottom:1px #000000 solid;}
.BBh td{border-bottom:1px #000000 dotted;}
</style>
</head>
<!--
<script src="inc/jquery-1.11.1.min.js"></script>
<script src="inc/jquery-ui.js"></script>
-->
<script src="inc/jquery-1.10.2.js"></script>
<script src="inc/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#EditSaveBut").click(function(){
// alert ("ddd")
})
})
function show(act,ori){
var bstr="";
switch(act){
case "createFolder":
var bstr="输入文件夹名称:";
var bstr= bstr +"<input type='text' name='dst' />";
var bstr= bstr +"<input type='submit' value='创建文件夹' />";
break;
case "createFile":
var bstr="输入新建文件名称:";
var bstr= bstr +"<input type='text' name='dst' />";
var bstr= bstr +"<input type='submit' value='新建文件' />";
break;
case "uploadFile":
var bstr="选择要上传的文件:";
var bstr= bstr +"<input type='file' name='dst' />";
var bstr= bstr +"<input type='submit' value='上传文件' />";
$("#myform").attr("enctype","multipart/form-data");
break;
case "renameFolder":
var bstr="请填写新文件夹名称:";
var bstr= bstr +"<input type='hidden' name='ori' value='"+ori+"' />";
var bstr= bstr +"<input type='text' name='dst' placeholder='重命名文件夹'/>";
var bstr= bstr +"<input type='submit' value='重命名文件夹' />";
break;
case "renameFile":
var bstr="请填写新文件名称:";
var bstr= bstr +"<input type='hidden' name='ori' value='"+ori+"' />";
var bstr= bstr +"<input type='text' name='dst' placeholder='无需后缀名'/>";
var bstr= bstr +"<input type='submit' value='重命名文件' />";
break;
case "copyFolder":
var bstr="将文件夹复制到:";
var bstr= bstr +"<input type='hidden' value='"+ori+"' name='ori' />";
var bstr= bstr +"<input type='text' name='dst' placeholder='目的文件夹'/>";
var bstr= bstr +"<input type='submit' value='复制文件夹' />";
break;
case "copyFile":
var bstr="将文件复制到:";
var bstr= bstr +"<input type='hidden' value='"+ori+"' name='ori' />";
var bstr= bstr +"<input type='text' name='dst' placeholder='目的文件夹必须存在'/>";
var bstr= bstr +"<input type='submit' value='复制文件' />";
break;
case "cutFolder":
var bstr="将文件夹剪切到:";
var bstr= bstr +"<input type='text' value='"+ori+"' name='ori' />";
var bstr= bstr +"<input type='text' name='dst' placeholder='目的文件夹自动创建'/>";
var bstr= bstr +"<input type='submit' value='剪切文件夹' />";
break;
case "cutFile":
var bstr="将文件剪切到:";
var bstr= bstr +"<input type='hidden' value='"+ori+"' name='ori' />";
var bstr= bstr +"<input type='text' name='dst' placeholder='目的文件夹'/>";
var bstr= bstr +"<input type='submit' value='剪切文件' />";
break;
case "delFolder":
if(window.confirm("确定删除文件夹?否则取消")){
location.href="?act=delFolder&ori="+ori;
};
break;
case "delFile":
if(window.confirm("确定删除文件?否则取消")){
location.href="?act=delFile&ori="+ori;
};
break;
};
$("#act").val(act);
$("#bstr").html(bstr);
};
function delFile(filename){
var path=$("#path").val();
// alert(path+"----"+filename);
if(window.confirm("确定删除?否则取消")){
location.href="?act=delFile&ori="+filename;
}
}
function showDetail(w,t,f){
var con="";
if(w=='View'){
con="<img src='"+f+"'>";
$("#DetailShow").html(con);
};
if(w=='Edit'){
var path=$("#path").val();
$.post("ajax.php",{"act":"getcon","fileGet":f},function(data,status){
con = con + "<form action='?' method='post'>";
con = con + "<input type='hidden' name='act' value='editContent'>";
con = con + "<input type='hidden' value='"+t+"' name='ori' /><br>";
con = con + "<input type='hidden' value='"+path+"' name='path'>"
con = con + "<textarea name='dst' cols='60' rows='10'>"+data+"</textarea><br>";
con = con + "<input type='submit' value='修改文件' />";
con = con + "</form>";
$("#DetailShow").html(con);
});
};
$("#DetailShow").dialog({
height:"auto",
width:"auto",
postition:{my:"center",at:"center",collision:"fit"},
modal:false,
draggable:true,
resizable:true,
title:w+":"+t,
show:"slide",
hide:"explode"
})
}
function goBack($back){
location.href='?path='+$back;
}
</script>
<body>
<h1>在线文件管理器</h1>
<div id="fitop">
【当前目录:<?php echo $path;?>】
【<span onclick="show('createFile');">新建文件</span>】
【<span onclick="show('createFolder');">新建文件夹</span>】
【<span onclick="show('uploadFile');">上传文件</span>】
【<span onclick="goBack('<?php echo $back;?>');">返回上层目录</span>】
<form action="?" method="post" id="myform" style="float:right">
<input type="hidden" id="act" name="act" value="" />
<input type="hidden" id="path" name="path" value="<?php echo $path;?>" />
<span id="bstr"></span>
</form>
</div>
<div id="DetailShow" style="display:none"></div>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr bgcolor="ABCDEF" class="TTh">
<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['dir']){
$i=1;
foreach($info['dir'] as $val){
$p=$path."/".$val;
?>
<tr class='BBh'>
<td><?php echo $i;?></td>
<td><a href="?path=<?php echo $p;?>"><?php echo $val;?></a></td>
<td><?php echo filetype($p)=="file"?"文件":"目录";?></td>
<td><?php $sum=0;echo transByte(dirSize($p));?></td>
<td><?php echo is_readable($p)?"可读":"不可";?></td>
<td><?php echo is_writable($p)?"可写":"不可";?></td>
<td><?php echo is_executable($p)?"可执行":"不可";?></td>
<td><?php echo date("Y-m-d",filectime($p));?></td>
<td><?php echo date("Y-m-d",filemtime($p));?></td>
<td><?php echo date("Y-m-d",fileatime($p));?></td>
<td class="Opt">
<!-- 文件夹在rename()操作时有问题 -->
【<a href="?path=<?php echo $p;?>">进入</a>】
【<span onclick="show('renameFolder','<?php echo $p;?>');">重命名</span>】
【<span onclick="show('copyFolder','<?php echo $p;?>');">复制到</span>】
【<span onclick="show('cutFolder','<?php echo $p;?>');">剪切到</span>】
【<span onclick="show('delFolder','<?php echo $p;?>');">删除</span>】
</td>
</tr>
<?php $i++; }}?>
<!--读取文件操作-->
<?php
if($info['file']){
(!$i)?$i=1:$i++;
foreach($info['file'] as $val){
$p=$path."/".$val;
?>
<tr class='BBh'>
<td><?php echo $i;?></td>
<td><?php echo $val;?></td>
<td><?php echo filetype($p)=="file"?"文件":"目录";?></td>
<td><?php echo transByte(filesize($p));?></td>
<td><?php echo is_readable($p)?"可读":"不可";?></td>
<td><?php echo is_writable($p)?"可写":"不可";?></td>
<td><?php echo is_executable($p)?"可执行":"不可";?></td>
<td><?php echo date("Y-m-d",filectime($p));?></td>
<td><?php echo date("Y-m-d",filemtime($p));?></td>
<td><?php echo date("Y-m-d",fileatime($p));?></td>
<td class="Opt">
【<a href="?act=downFile&path=<?php echo $path;?>&filename=<?php echo $p;?>">下载</a>】
【<span onclick="show('renameFile','<?php echo $p;?>');">重命名</span>】
【<span onclick="show('copyFile','<?php echo $p;?>');">复制到</span>】
【<span onclick="show('cutFile','<?php echo $p;?>');">剪切到</span>】
【<span onclick="show('delFile','<?php echo $p;?>');">删除</span>】
<?php $ext=strtolower(end(explode(".",$val)));
$imageExt=array("gif","jpg","jpeg","png");
if(in_array($ext,$imageExt)){
?>
【<span onclick="showDetail('View','<?php echo $val;?>','<?php echo $p;?>');">浏览</span>】
<?php }else{?>
【<span onclick="showDetail('Edit','<?php echo $val;?>','<?php echo $p;?>');">编辑</span>】
<?php }?>
</td>
</tr>
<?php $i++;}}?>
</table>
</body>
</html>