3.2.1我发现有又拍云的上传驱动,所以把上传函数改造了一下以便于一次配置后可以自动判断上传
/*
自动获取上传配置上传函数
*/
function filed($config='',$path=''){
$Upload_type=C('upload_type');
$upload_driver=C($Upload_type);
if (!$config) {
$config = array(
'maxSize' => 3145728,
'rootPath' => 'Upload',
'savePath' => $path,
'saveName' => 'time',
'exts' => array('jpg', 'gif', 'png', 'jpeg'),
'autoSub' => true,
'subName' => array('date','Ymd'),
'replace' => true,
);
}
// 实例化上传类
$upload = new \Think\Upload($config,$Upload_type,$upload_driver);
$path?true:$upload->savePath='/';
$info = $upload->upload(); // 上传文件
if(!$info) {
$data['type']=0;
$data['msg']=$upload->getError();
return $data; // 上传错误提示错误信息
}else{
$request=array();
foreach ($info as $key => $value) {
$request[]=$value;
}
if ($Upload_type!=='Local') {
for($i=0;$i<count($request);$i++){
$res[]='http://'.C('files_domain').'/'.$config['rootPath'].$request[$i]['savepath'].$request[$i]['savename'];
}
}else{
for($i=0;$i<count($request);$i++){
$res[]=__ROOT__.'/'.$config['rootPath'].$request[$i]['savepath'].$request[$i]['savename'];
}
}
$data['type']=1;
$data['msg']=$res;
return $data;
}
}
配置项增加
<?php return array(
'files_domain'=>'文件空间绑定域名',
'upload_type'=>'Upyun',//或Local
'upyun'=>array(
'bucket'=>'空间名',
'username'=>'用户名',
'password'=>'密码',
'host'=>'v0.api.upyun.com'
),
);
?>