Copy, delete, r...LOGIN

Copy, delete, rename files

Modify filemanager_html.php code:

<?php
<!--    循环输出文件列表-->
    <?php
    foreach($file_list['file'] as $v):
    ?>
    <tr>
        <td><img src="./img/file.png"><?php echo $v['filename'];?></td>
        <td><?php echo $v['filemtime'];?></td>
        <td><?php echo $v['filesize'];?>KB</td>
        <td>
            <a href="?path=<?php echo $v['filepath'];?>&a=rename">重命名</a>
            <a href="?path=<?php echo $v['filepath'];?>&a=copy">复制</a>
            <a href="?path=<?php echo $v['filepath'];?>&a=del">删除</a>
        </td>
    </tr>
    <?php endforeach;?>

Modify filemanager.php code:

<?php
//获取操作参数
$action=isset($_GET['a'])?$_GET['a']:'';
switch ($action){
    //返回上一级目录
    case 'prev':
        $path=dirname($path);
        break;
    //其他操作...
    case 'copy':
        if($file){
            if(file_exists("$path/$file.bak")){
                die('文件名冲突,复制失败');
            }
            if(!copy("$path/$file","$path/$file.bak")){
                die('复制文件失败');
            }
        }
        break;
    case 'del':
        if($file){
            unlink("$path/$file");
        }
        break;
    case 'rename':
        if(!empty($_POST)){
            //获取目标文件名
            $target=isset($_POST['target'])?trim($_POST['target']):'';
            //如果待操作文件不为空,则进行重命名操作
            if($file && $target){
                if(file_exists("$path/$target")){
                    die('目标文件已经存在');
                }
                rename("$path/$file","$path/$target");
            }
            //重命名完成后跳转
            header('Localtion:?path='.$path);
        }
        break;
}

Rename needs to be in 'return Add a piece of code to the upper directory to rename the new file:

<?php
<!--重命名操作区-->
<?php  if($action=='rename'):?>
<form method="post">
    将<span><?php echo $file;?></span>
    重命名为:<input type="text" value="<?php echo $file;?>" name="target" />
    <input type="submit" value="确定"/>
</form>
<?php endif;?>

Copy effect display:


微信图片_20180301170355.png

Delete display:

微信图片_20180301170533.png微信图片_20180301170536.png

Rename display:

微信图片_20180301170738.png微信图片_20180301170741.png微信图片_20180301170744.png

<?php echo "复制,删除,重命名操作";
submitReset Code
ChapterCourseware