Home  >  Article  >  php教程  >  3.2.1自动获取上传配置上传

3.2.1自动获取上传配置上传

WBOY
WBOYOriginal
2016-06-07 11:42:091032browse

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

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
Previous article:图片上传Next article:单例模式实现购物车