创建文件夹功能

1,前端显示创建按钮

在netdisk_html.php页面加入以下代码:

<?php
<form method="post">
    新建文件夹:<input type="text" name="newfolder">
    <input type="submit" value="创建">
</form>

可以在input框内写需要创建的文件夹名然后点击创建通过post方式提交

2,在index.php页面获取

因为在index.php文件引入了require('netdisk_html.php'),所以默认提交就是当前页面,不需要再写action="index.php",当然写了也不会报错

获取到post提交的数据对数据执行新建文件夹功能即可,具体代码如下:

<?php
//获取表单传来的数据
$newfolder=isset($_POST['newfolder'])?trim($_POST['newfolder']):"";
//创建文件夹功能
if($newfolder==''){
//    echo "创建文件夹失败";
}else{
    //不能建已经存在的文件夹--进行判断
    $sql="select folder_name from netdisk_folder where folder_pid=$folder_id AND folder_name='$newfolder'";
    $allfolder=fetchRow($sql);
    if($allfolder){
        echo "文件名不能重复";
    }else{
        //正常创建的情况下
        $sql="insert into netdisk_folder (folder_name,folder_time,folder_path,folder_pid) values('$newfolder',now(),$folder_id,$folder_id)";
        $result=query($sql);
        if($result){
//            echo '添加成功';
        }else{
            echo '添加失败';
        }
    }
}

3,页面展示:

微信图片_20180302174853.png微信图片_20180302174856.png


继续学习
||
<?php echo "创建文件夹功能"; ?>
提交重置代码
章节
笔记
提问
课件
反馈
捐赠