(17)复制文件

① 复制文件通过copy($src,$dst) 来实现

② 检测目标目录是否存在,如果存在则继续检测目标目录中是否存在同名文件,如果不存在则复制成功

file.func.php 中添加:

/*
复制文件
*/
function copyFile($filename,$dstname){
if(file_exists($dstname)){
if(file_exists($dstname.'/'.basename($filename))){
return '存在同名文件';
}else{
if(copy($filename,$dstname.'/'.basename($filename))){
return '文件复制成功';
}else{
return '文件复制失败';
}
}
}else{
return '目标目录不存在';
}
}

file.func.php 完整代码:

<?php
/*
转换字节大小
*/
function transByte($size){
$arr = array('B','KB','MB','GB','TB','EB');
$i = 0;
while($size > 1024){
$size /= 1024;
$i++;
}
return round($size,2).' '.$arr[$i];
} /*
创建文件
*/
/*
注意:
createFile函数前面的正则表达式部分使用了 basename 函数,这个函数会过滤掉所有的 / 斜杠。
这样在文件名中任意输入 / 不会引起报错。
*/
function createFile($filename){
if(checkFilename(end(explode('/',$filename)))){
//检测当前目录现是否存在同名文件
if(!file_exists($filename)){
//通过touch方法创建文件
if(@touch($filename)){
return '文件创建成功';
}else{
return '文件创建失败';
}
}else{
return '文件已存在,请重命名后创建';
}
}else{
return '非法文件名';
}
} /*
重命名文件
@param newname string 重命名之后的文件名
@param oldname string 重命名之前的文件名
*/
function renameFile($oldname,$newname){
if(checkFilename($newname)){
$path = dirname($oldname);
if(!file_exists($path.'/'.$newname)){
if(rename($oldname,$path.'/'.$newname)){
return '重命名成功';
}else{
return '重命名失败';
}
}else{
return '文件名已存在,请重新命名';
}
}else{
return '非法文件名';
}
} /*
检测文件名合法性
*/
function checkFilename($filename){
//验证文件名合法性,是否包含特殊字符 \ / : | * " ? < >
$pattern = '/[\/,\*,<,>,\?\|,\\\\,:,"]/'; // * < > | ? : "有效
if(!preg_match($pattern, $filename)){
return true;
}else{
return false;
}
} /*
删除文件
*/
function delFile($filename){
if(unlink($filename)){
return '文件成功删除';
}else{
return '文件删除失败';
}
} /*
下载文件
*/
function downFile($filename){
header('content-disposition:attachment;filename=emperor_'.basename($filename));
header('content-length:'.filesize($filename));
readfile($filename);
} /*
复制文件
*/
function copyFile($filename,$dstname){
if(file_exists($dstname)){
if(file_exists($dstname.'/'.basename($filename))){
return '存在同名文件';
}else{
if(copy($filename,$dstname.'/'.basename($filename))){
return '文件复制成功';
}else{
return '文件复制失败';
}
}
}else{
return '目标目录不存在';
}
}

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);
}else if($act == 'copyFile'){
//复制文件
//复制文件夹
$str = <<<EOF
<form action='index.php?act=doCopyFile' method='post'>
请将文件复制到:<input type="text" name="dstname" placeholder="将文件复制到">
<input type="hidden" name="path" value='$path'>
<input type="hidden" name="filename" value='$filename'>
<input type='submit' value='复制文件'>
</form>
EOF;
echo $str;
}else if($act == 'doCopyFile'){
$dstname = $_REQUEST['dstname'];
$mes = copyFile($filename,$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="" alt="" 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="data:images/<?php echo $src;?>" alt="" title='文件'></td>
<td><?php echo transByte(filesize($p));?></td>
<td><?php $src = is_readable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" title='可读'></td>
<td><?php $src = is_writeable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" title='可写'></td>
<td><?php $src = is_executable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" 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="data:images/show.png" class="small" alt=""></a> <?php }else{ ?>
<a href="index.php?act=showContent&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='查看'><img src="data:images/show.png" class="small" alt=""></a>
<?php
}
?> <a href="index.php?act=editContent&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='修改'><img src="data:images/edit.png" class="small" alt=""></a>
<a href="index.php?act=renameFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='重命名'><img src="data:images/rename.png" class="small" alt=""></a>
<a href="index.php?act=copyFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='复制'><img src="data:images/copy.png" class="small" alt=""></a>
<a href="" title='剪切'><img src="data:images/cut.png" class="small" alt=""></a>
<a href="javascript:void(0)" onclick="delFile('<?php echo $p;?>')" title='删除'><img src="data:images/delete.png" class="small" alt=""></a>
<a href="index.php?act=downFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='下载'><img src="data:images/download.png" class="small" alt=""></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="data:images/<?php echo $src;?>" alt="" title='文件'></td>
<td><?php //$size = 0; echo transByte(dirSize($p));?></td>
<td><?php $src = is_readable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" title='可读'></td>
<td><?php $src = is_writeable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" title='可写'></td>
<td><?php $src = is_executable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" 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="data:images/show.png" class="small" alt=""></a>
<a href="index.php?act=renameFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title='重命名'><img src="data:images/rename.png" class="small" alt=""></a>
<a href="index.php?act=copyFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title='复制'><img src="data:images/copy.png" class="small" alt=""></a>
<a href="index.php?act=cutFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title='剪切'><img src="data:images/cut.png" class="small" alt=""></a>
<a href="javascript:void(0)" onclick="delFolder('<?php echo $p;?>','<?php echo $path;?>')" title='删除'><img src="data:images/delete.png" class="small" alt=""></a>
<a href="index.php?act=downFile&filename=<?php echo $p;?>" title='下载'><img src="data:images/download.png" class="small" alt=""></a>
</td>
</tr>
<?php
$i++;
}
}
?>
</table>
</form>
<script src='common.js'></script>
</body>
</html>

(18)剪切文件

① 剪切文件通过rename($oldname,$newname) 来实现

② 检测目标目录是否存在,如果存在则继续检测目标目录中是否存在同名文件,如果不存在则剪切成功

(注:只需要把复制文件的 copy 函数改成 rename 函数,再修改文字信息即可)

file.func.php 中添加:

/*
剪切文件
*/
function cutFile($filename,$dstname){
if(file_exists($dstname)){
if(file_exists($dstname.'/'.basename($filename))){
return '存在同名文件';
}else{
if(rename($filename,$dstname.'/'.basename($filename))){
return '文件剪切成功';
}else{
return '文件剪切失败';
}
}
}else{
return '目标目录不存在';
}
}

file.func.php 完整代码:

<?php
/*
转换字节大小
*/
function transByte($size){
$arr = array('B','KB','MB','GB','TB','EB');
$i = 0;
while($size > 1024){
$size /= 1024;
$i++;
}
return round($size,2).' '.$arr[$i];
} /*
创建文件
*/
/*
注意:
createFile函数前面的正则表达式部分使用了 basename 函数,这个函数会过滤掉所有的 / 斜杠。
这样在文件名中任意输入 / 不会引起报错。
*/
function createFile($filename){
if(checkFilename(end(explode('/',$filename)))){
//检测当前目录现是否存在同名文件
if(!file_exists($filename)){
//通过touch方法创建文件
if(@touch($filename)){
return '文件创建成功';
}else{
return '文件创建失败';
}
}else{
return '文件已存在,请重命名后创建';
}
}else{
return '非法文件名';
}
} /*
重命名文件
@param newname string 重命名之后的文件名
@param oldname string 重命名之前的文件名
*/
function renameFile($oldname,$newname){
if(checkFilename($newname)){
$path = dirname($oldname);
if(!file_exists($path.'/'.$newname)){
if(rename($oldname,$path.'/'.$newname)){
return '重命名成功';
}else{
return '重命名失败';
}
}else{
return '文件名已存在,请重新命名';
}
}else{
return '非法文件名';
}
} /*
检测文件名合法性
*/
function checkFilename($filename){
//验证文件名合法性,是否包含特殊字符 \ / : | * " ? < >
$pattern = '/[\/,\*,<,>,\?\|,\\\\,:,"]/'; // * < > | ? : "有效
if(!preg_match($pattern, $filename)){
return true;
}else{
return false;
}
} /*
删除文件
*/
function delFile($filename){
if(unlink($filename)){
return '文件成功删除';
}else{
return '文件删除失败';
}
} /*
下载文件
*/
function downFile($filename){
header('content-disposition:attachment;filename=emperor_'.basename($filename));
header('content-length:'.filesize($filename));
readfile($filename);
} /*
复制文件
*/
function copyFile($filename,$dstname){
if(file_exists($dstname)){
if(file_exists($dstname.'/'.basename($filename))){
return '存在同名文件';
}else{
if(copy($filename,$dstname.'/'.basename($filename))){
return '文件复制成功';
}else{
return '文件复制失败';
}
}
}else{
return '目标目录不存在';
}
} /*
剪切文件
*/
function cutFile($filename,$dstname){
if(file_exists($dstname)){
if(file_exists($dstname.'/'.basename($filename))){
return '存在同名文件';
}else{
if(rename($filename,$dstname.'/'.basename($filename))){
return '文件剪切成功';
}else{
return '文件剪切失败';
}
}
}else{
return '目标目录不存在';
}
}

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);
}else if($act == 'copyFile'){
//复制文件
//复制文件夹
$str = <<<EOF
<form action='index.php?act=doCopyFile' method='post'>
请将文件复制到:<input type="text" name="dstname" placeholder="将文件复制到">
<input type="hidden" name="path" value='$path'>
<input type="hidden" name="filename" value='$filename'>
<input type='submit' value='复制文件'>
</form>
EOF;
echo $str;
}else if($act == 'doCopyFile'){
$dstname = $_REQUEST['dstname'];
$mes = copyFile($filename,$path.'/'.$dstname);
alertMes($mes,$redirect);
}else if($act == 'cutFile'){
//复制文件
//复制文件夹
$str = <<<EOF
<form action='index.php?act=doCutFile' method='post'>
请将文件剪切到:<input type="text" name="dstname" placeholder="将文件剪切到">
<input type="hidden" name="path" value='$path'>
<input type="hidden" name="filename" value='$filename'>
<input type='submit' value='剪切文件'>
</form>
EOF;
echo $str;
}else if($act == 'doCutFile'){
$dstname = $_REQUEST['dstname'];
$mes = cutFile($filename,$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="" alt="" 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="data:images/<?php echo $src;?>" alt="" title='文件'></td>
<td><?php echo transByte(filesize($p));?></td>
<td><?php $src = is_readable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" title='可读'></td>
<td><?php $src = is_writeable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" title='可写'></td>
<td><?php $src = is_executable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" 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="data:images/show.png" class="small" alt=""></a> <?php }else{ ?>
<a href="index.php?act=showContent&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='查看'><img src="data:images/show.png" class="small" alt=""></a>
<?php
}
?> <a href="index.php?act=editContent&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='修改'><img src="data:images/edit.png" class="small" alt=""></a>
<a href="index.php?act=renameFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='重命名'><img src="data:images/rename.png" class="small" alt=""></a>
<a href="index.php?act=copyFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='复制'><img src="data:images/copy.png" class="small" alt=""></a>
<a href="index.php?act=cutFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='剪切'><img src="data:images/cut.png" class="small" alt=""></a>
<a href="javascript:void(0)" onclick="delFile('<?php echo $p;?>')" title='删除'><img src="data:images/delete.png" class="small" alt=""></a>
<a href="index.php?act=downFile&path=<?php echo $path;?>&filename=<?php echo $p;?>" title='下载'><img src="data:images/download.png" class="small" alt=""></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="data:images/<?php echo $src;?>" alt="" title='文件'></td>
<td><?php //$size = 0; echo transByte(dirSize($p));?></td>
<td><?php $src = is_readable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" title='可读'></td>
<td><?php $src = is_writeable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" title='可写'></td>
<td><?php $src = is_executable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" class="small" alt="" 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="data:images/show.png" class="small" alt=""></a>
<a href="index.php?act=renameFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title='重命名'><img src="data:images/rename.png" class="small" alt=""></a>
<a href="index.php?act=copyFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title='复制'><img src="data:images/copy.png" class="small" alt=""></a>
<a href="index.php?act=cutFolder&path=<?php echo $path;?>&dirname=<?php echo $p;?>" title='剪切'><img src="data:images/cut.png" class="small" alt=""></a>
<a href="javascript:void(0)" onclick="delFolder('<?php echo $p;?>','<?php echo $path;?>')" title='删除'><img src="data:images/delete.png" class="small" alt=""></a>
<a href="index.php?act=downFile&filename=<?php echo $p;?>" title='下载'><img src="data:images/download.png" class="small" alt=""></a>
</td>
</tr>
<?php
$i++;
}
}
?>
</table>
</form>
<script src='common.js'></script>
</body>
</html>

Web 在线文件管理器学习笔记与总结(17)复制文件 (18)剪切文件的更多相关文章

  1. Web 在线文件管理器学习笔记与总结(19)上传文件

    dir.func.php 中添加方法: /* 上传文件 */ function uploadFile($fileInfo,$path,$allowExt = array('jpg','jpeg','p ...

  2. Web 在线文件管理器学习笔记与总结(13)重命名文件夹(14)复制文件夹

    (13)重命名文件夹 ① 重命名文件夹通过 rename($oldname,$newname) 实现 ② 检测文件夹名是否符合规范 ③ 检测当前目录中是否存在同名文件夹名称,如果不存在则重命名成功 i ...

  3. Web 在线文件管理器学习笔记与总结(7)重命名文件

    rename($oldname,$newname) 重命名文件或目录 <<<EOF EOF; 使用heredoc 技术,来部分实现界面与代码的准分离 重命名时,需要验证新文件名的合法 ...

  4. Web 在线文件管理器学习笔记与总结(15)剪切文件夹 (16)删除文件夹

    (15)剪切文件夹 ① 通过rename($oldname,$newname) 函数实现剪切文件夹的操作 ② 需要检测目标文件夹是否存在,如果存在还要检测目标目录中是否存在同名文件夹,如果不存在则剪切 ...

  5. Web 在线文件管理器学习笔记与总结(11)获取文件夹信息 (12)返回上一级操作

    (11)获取文件夹信息 文件夹没有修改操作. index.php: <?php require 'dir.func.php'; require 'file.func.php'; require ...

  6. Web 在线文件管理器学习笔记与总结(10)查看文件夹中的内容

    ① 读取文件夹大小 a. 封装计算文件夹大小的函数 b.  打开文件夹 c. 循环判断文件夹下的内容是文件还是文件夹,如果是文件,则累积相加文件的大小:如果是文件夹,则递归调用该函数 注意两个问题: ...

  7. Web 在线文件管理器学习笔记与总结(9)下载文件

    ① 普通形式的文件可以使用超链接形式下载 <a href = '下载文件名'>点击下载</a> ② 如果下载图片.html 等类型的文件,使用header() 函数发送网页头信 ...

  8. Web 在线文件管理器学习笔记与总结(8)删除文件

    unlink($filename) 删除文件 index.php: <?php require 'dir.func.php'; require 'file.func.php'; require ...

  9. Web 在线文件管理器学习笔记与总结(6)jQuery UI 预览图片

    ① 查看文件内容,如果文件是图片类型,点击直接查看图片: ② 如果不是图片类型,显示文件中的内容: ③ 使用 jQuery UI 中的 Dialog 显示图片 a.引入: <script src ...

随机推荐

  1. C++ friend

    如果类A希望类B可以访问它的私有成员, 可以把类B设置为友元类. // 类A,希望把私有成员公开给类B class A {     friend class B;// 把B设置为友元类 public: ...

  2. 解决Windows和Ubuntu时间不一致的问题

    问题原因是使用的时间不一致导致的.win10直接从bios读出来的时间认为就是实际时间,ubuntu认为加上8个小时 后的才是.win10用的rtc ,ubuntu用的utc 在ubuntu16.04 ...

  3. UML中的关联关系

    UML中的关联关系其内在意思就是has a 如图:  相对于依赖关系,关联关系在代码中有所体现.上图中的关联关系在代码中体现为       其中water 中将Climate作为其中的属性. 当然,关 ...

  4. Ninja - chromium核心构建工具

    转自:http://guiquanz.me/2014/07/28/a_intro_to_Ninja/ Ninja - chromium核心构建工具Jul 28, 2014 [在线编辑] 缘由 经过上次 ...

  5. FileUpload之FileItem

    转自:http://asialee.iteye.com/blog/706079 FileItem类主要是封装了一个File Item或者是FormItem,它的主要的方法如下,需要说明的是对于Form ...

  6. ORCFILE,ParquetFile,CubeFile使用场景区别

    这个其实是转自杭州第三次spark meetingup,华为的李昆大神的分享. OLAP分析场景 ORC File Parquet File Cube File Full scan one dimen ...

  7. awk命令

    awk 手册   原文 Table of Contents 1. awk简介 2. awk命令格式和选项 2.1. awk的语法有两种形式 2.2. 命令选项 3. 模式和操作 3.1. 模式 3.2 ...

  8. UVa1401 Remember the Word(DP+Trie树)

    题目给定一个字符串集合有几种方式拼成一个字符串. dp[i]表示stri...strlen-1的方案数 dp[len]=1 dp[i]=∑dp[j](stri...strj-1∈SET) 用集合的字符 ...

  9. POJ2047 Concert Hall Scheduling(最小费用最大流)

    题目大概是有两个音乐厅,有n个乐队申请音乐厅,他们必须从第ii天到第ji天连续开音乐会且他们的开价是wi,每天每个音乐厅都只能供一个乐队进行音乐会.问接受哪些乐队的申请,获利最多能多少. 这题相当于在 ...

  10. HDU4057 Rescue the Rabbit(AC自动机+状压DP)

    题目大概是给几个DNA片段以及它们各自的权值,如果一个DNA包含某个片段那么它的价值就加上这个片段的权值,同时包含多个相同DNA片段也只加一次,问长度l的DNA可能的最大价值. 与HDU2825大同小 ...