美文网首页
Tp5 封装上传单张图片

Tp5 封装上传单张图片

作者: 风度翩翩的程序猿 | 来源:发表于2020-05-22 17:29 被阅读0次
//单个上传图片
    public function synchroUploadImg()
    {
        $ret = array('ret' => 'no', 'imgurl' => '');
        $upload = $this->getUploadClass(); // 这里是上传图片的设置
        $info = $upload->uploadOne($_FILES[$filename]);
        if (!$info) {
            $ret['imgurl'] = $upload->getError(); //返回上传失败的原因
        } else {
            $ret['ret'] = 'yes';
            $ret['imgurl'] = $info['savepath'] . $info['savename']; // 返回上传的地址
        }
        return $ret;
    }
 public function getUploadClass()
    {
        $path = C('IMG_FOLDER');

        $upload = new \Think\Upload();
        $upload->maxSize = 0;
        $upload->rootPath = '.' . $path;
        $upload->savePath = '';
        $upload->saveName = array('uniqid', '');
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg', 'mp4', 'docx', 'pdf');
        $upload->autoSub = true;
        $upload->subName = array('date', 'Ymd');
        return $upload;
    }

谢谢大家,有个好的方法,望大佬们前来评论!!!!!!

相关文章

网友评论

      本文标题:Tp5 封装上传单张图片

      本文链接:https://www.haomeiwen.com/subject/glhcahtx.html