最近項目中用到了七牛雲服務,來分享一下thinkphp使用七牛雲來進行文件上傳php
1.首先在七牛雲建立一個空間,例如空間名爲test。獲取secrectKey,accessKeythinkphp
2.在thinkphp的Application/Common/Conf/config.php裏添加七牛雲的配置dom
'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.上傳文件 code
fucntion upload(){
$setting=C('UPLOAD_SITEIMG_QINIU');
$Upload = new \Think\Upload($setting);
$info = $Upload->upload($_FILES);
print_r($info);
}blog