最近项目中用到了七牛云服务,来分享一下thinkphp使用七牛云来进行文件上传
1.首先在七牛云创建一个空间,例如空间名为test。获取secrectKey,accessKey
2.在thinkphp的Application/Common/Conf/config.php里添加七牛云的配置
'UPLOAD_SITEIMG_QINIU_TEST'=>array(
'maxSize' => 12 * 1024 * 1024, //限制上传文件大小
'rootPath' => './',
'saveName' => array ('uniqid', ''),
'driver' => 'Qiniu',
'driverConfig' => array (
'secrectKey' => 'xxxxxxxx',
'accessKey' => 'xxxxxxxxx',
'domain' => 'ofjo26fgy.bkt.clouddn.com',
'bucket' => 'testroom',
)
),
3.上传文件
fucntion upload(){
$setting=C('UPLOAD_SITEIMG_QINIU');
$Upload = new \Think\Upload($setting);
$info = $Upload->upload($_FILES);
print_r($info);
}