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 $res[]='http://'.c('files_domain').'/'.$config['rootpath'].$request[$i]['savepath'].$request[$i]['savename'];
}
}else{
for($i=0;$i $res[]=__root__.'/'.$config['rootpath'].$request[$i]['savepath'].$request[$i]['savename'];
}
}
$data['type']=1;
$data['msg']=$res;
return $data;
}
}配置项增加'文件空间绑定域名',
'upload_type'=>'upyun',//或local
'upyun'=>array(
'bucket'=>'空间名',
'username'=>'用户名',
'password'=>'密码',
'host'=>'v0.api.upyun.com'
),
);
?>
ad:真正免费,域名+虚机+企业邮箱=0元