前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Thinkphp3.2.3FTP上传文件同名覆盖问题

Thinkphp3.2.3FTP上传文件同名覆盖问题

作者头像
苦咖啡
发布2018-04-28 14:08:05
1.9K0
发布2018-04-28 14:08:05
举报
文章被收录于专栏:我的博客我的博客
//原代码在\ThinkPHP\Library\Think\Upload\Driver\Ftp.class.php
//大概在94行左右
    /**
     * 保存指定文件
     * @param  array   $file    保存的文件信息
     * @param  boolean $replace 同名文件是否覆盖
     * @return boolean          保存状态,true-成功,false-失败
     */
    public function save($file, $replace=true) {
        $filename = $this->rootPath . $file['savepath'] . $file['savename'];

        /* 不覆盖同名文件 */
        // if (!$replace && is_file($filename)) {
        //     $this->error = '存在同名文件' . $file['savename'];
        //     return false;
        // }

        /* 移动文件 */
        if (!ftp_put($this->link, $filename, $file['tmp_name'], FTP_BINARY)) {
            $this->error = '文件上传保存错误!';
            return false;
        }
        return true;
    }
     //源代码当中屏蔽了同名覆盖的判断
    //需要改成
     //构造函数当中rootPath设置有误
     $this->rootPath = ftp_pwd($this->link);
    /**
     * 保存指定文件
     * @param  array   $file    保存的文件信息
     * @param  boolean $replace 同名文件是否覆盖
     * @return boolean          保存状态,true-成功,false-失败
     */
    public function save($file, $replace=true) {
        $filename = $this->rootPath . $file['savepath'] . $file['savename'];
        /* 不覆盖同名文件 */
        if (!$replace) {
            ftp_chdir($this->link, $this->rootPath . $file['savepath']);
            $ftpFileList = ftp_nlist($this->link, ".");
            if(in_array($file['savename'], $ftpFileList)) {
                $this->error = '存在同名文件' . $file['savename'];
                return false;
            }
        }
        /* 移动文件 */
        if (!ftp_put($this->link, $filename, $file['tmp_name'], FTP_BINARY)) {
            $this->error = '文件上传保存错误!';
            return false;
        }
        return true;
    }
//使用配置config
Array
(
    [maxSize] => 734003200
    [savePath] => 
    [saveName] => test
    [exts] => Array
        (
            [0] => jpeg
            [1] => bmp
            [2] => zip
            [3] => jpg
        )

    [subName] => 2016/test
    [rootPath] => 
)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年6月3日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档