Home >php教程 >php手册 >Thinkphp3.2.3又拍云(upyun)驱动上传文件

Thinkphp3.2.3又拍云(upyun)驱动上传文件

WBOY
WBOYOriginal
2016-06-07 11:38:221888browse

Thinkphp3.2.3一则使用又拍云驱动上传文件的实现,分享给需要集成又拍云文件上传的小伙伴们。
首先在项目任意的配置文件加入如下配置:
'FILE_UPLOAD_TYPE' => 'Upyun',
'UPLOAD_TYPE_CONFIG' => array(
//又拍云host,默认即可
'host' => 'v0.api.upyun.com',
//又拍云创建的空间名
'bucket' => '',
//对应空间的操作员名称
'username' => '',
//操作员口令
'password' => ''
),

controller实现:


namespace Home\Controller;
use Think\Upload;


class UploadController extends Controller {

public function uploadImage(){
$upload = new Upload(); //文件上传对象实例化
$upload->rootPath = './'; //根目录,默认./即可
$upload->savePath = 'avatar/'; //子目录, 可为空
$upload->autoSub = TRUE; //是否自动生成二级子目录
$upload->subName = array('date','Ymd'); //子目录规则
$info = $upload->upload(); //文件上传
if(!$info) {
$this->error($upload->getError()); //获取错误信息
}else{
// 上传成功后获取上传文件信息,进行后续处理
//mode操作
//$this->ajaxReturn() 可以进行文件的ajax上传(需要客户端js脚本配合)
}

}
}

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn