第三方oss储存修改轻微bug


今天来研究了下 框架的七牛云存储 发现一个 问题 就是同一个文件传上去会继续想第三方存储传送文件,这样对未来很不友好会出现很多沉淀问题第三方存储上面。




具体代码发上来把!


修改Upload.php 文件一下部分为:



 //检查文件是否已经存在

        $assetModel = new AssetModel();

        $objAsset   = $assetModel->where(["user_id" => $userId, "file_key" => $arrInfo["file_key"]])->find();

        if ($objAsset) {

            $arrAsset = $objAsset->toArray();

            //$arrInfo["url"] = $this->request->domain() . $arrAsset["file_path"];

            $arrInfo["file_path"] = $arrAsset["file_path"];

            if (file_exists('./upload/' . $arrInfo["file_path"])) {

                @unlink($strSaveFilePath); // 删除已经上传的文件

            } else {

                rename($strSaveFilePath, './upload/' . $arrInfo["file_path"]);

            }


        } else {

            $assetModel->data($arrInfo)->allowField(true)->save();

            

            $storage = cmf_get_option('storage');


            if (empty($storage['type'])) {

                $storage['type'] = 'Local';

            }


            if ($storage['type'] != 'Local') { //  增加存储驱动

                $storage = new Storage($storage['type'], $storage['storages'][$storage['type']]);

                $result  = $storage->upload($arrInfo["file_path"], './upload/' . $arrInfo["file_path"], $fileType);

                if (file_exists('./upload/' . $arrInfo["file_path"])) {

                    @unlink($strSaveFilePath); // 删除已经上传的文件

                }

                if (!empty($result)) {

                    return array_merge([

                        'filepath'    => $arrInfo["file_path"],

                        "name"        => $arrInfo["filename"],

                        'id'          => $strId,

                        'preview_url' => cmf_get_root() . '/upload/' . $arrInfo["file_path"],

                        'url'         => cmf_get_root() . '/upload/' . $arrInfo["file_path"],

                    ], $result);

                }

            }

        }


        //删除临时文件

//        for ($index = 0; $index < $chunks; $index++) {

//            // echo $targetDir . "{$strFilePath}_{$index}.part";

//            @unlink($targetDir . "{$strFilePath}_{$index}.part");

//        }

        @rmdir($targetDir);


        return [

            'filepath'    => $arrInfo["file_path"],

            "name"        => $arrInfo["filename"],

            'id'          => $strId,

            'preview_url' => cmf_get_root() . '/upload/' . $arrInfo["file_path"],

            'url'         => cmf_get_root() . '/upload/' . $arrInfo["file_path"],

        ];

    }


打赏

评论

暂时关闭,稍后恢复~
文档请看10遍以上!有问题可加QQ群!
发表话题

源素材推荐

提问必知

0.话题发布后没及时显示,请联系官方QQ群管理;
1.话题支持代码,qq截屏直接粘贴,和QQ群一样;
2.问题描述清,比如服务器版本,程序版本;
3.能上代码,就不用文字;
4.把问题发到话题后再发QQ群;
5.如果感觉回复者解答的不错,可以发红包!
6.多帮助别人也是对自己的锻炼!
7.付费讨论中只有提问者和付费用户才可以查看回复

积分规则

1.评论积分+1;每天最多10次奖励
2.发布话题积分+1;每天最多5次奖励
3.垃圾评论积分-500;
4.黄色,暴力,违反我国法律评论直接封号


ThinkCMF 8.0.1发布啦!节日快乐! 立即体验!