Home > php教程 > php手册 > body text

3.2.1自动获取上传配置上传

WBOY
Release: 2016-06-07 11:42:09
Original
1050 people have browsed it

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元

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!