thinkphp 3.2.3 FTP上传文件

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()参数为一维数组

你可能感兴趣的:(PHP)