thinkphp 3.2.3 FTP上传文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33845254/article/details/81298980
public function ftpUpload()
    {
        $ftpfile = $_FILES['ftpfile'];
        $filecfg = C('DOWNLOAD_UPLOAD');
        $config = array(
            'maxSize'    =>   '',
            'rootPath'   =>    '',
            'savePath'   =>    '/Upload/',
            'saveName'   =>    array('uniqid', ''),
            'exts'       =>    'jpg,gif,png,jpeg,zip,rar,tar,gz,7z,doc,docx,txt,xml,ppt,pptx,xls,xlsx,pdf,tif,tiff,bmp',
            'autoSub'    =>   true,
            'subName'    =>    array('date', 'Y-m-d'),
        );

        $ftpConfig     =    array(        
                'host'     => C('FTPHOST'), //服务器
                'port'     => C('FTPPORT'), //端口
                'timeout'  => C('FTPTIMEOUT'), //超时时间
                'username' => C('FTPUSERNAME'), //用户名
                'password' => C('FTPPASSWORD'), //密码
        );
 
        $upload = new \Think\Upload($config,'Ftp',$ftpConfig);// 实例化上传类
        $info = $upload->uploadOne($ftpfile);
        //这里判断是否上传成功
        if ($info) {
            print_r($info);
            exit();
        } else {
            //输出错误信息
            exit($upload->getError());
        }

    }

注意事项:  

调用上传时,upload()参数为二维数组,uploadOne()参数为一维数组

展开阅读全文

没有更多推荐了,返回首页