Home >php教程 >php手册 >Thinkphp3.1配置阿里云oss开放存储云服务

Thinkphp3.1配置阿里云oss开放存储云服务

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 11:37:141382browse

把站点的图片存储到oss,取代图片服务器, 便于服务器扩展和后期站点集群。
目录结构上图:Thinkphp3.1配置阿里云oss开放存储云服务
上代码://上传项目图片到阿里oss服务器<br> function upload_file_to_alioss($data, $borrow_id)<br> {<br>     $ossinfo = C("OSS_SERVERINFO");<br>     import("ORG.Alioss.alioss");<br>     $oss = new ALIOSS($access_id = $ossinfo['OSS_ACCESS_ID'], $access_key = $ossinfo['OSS_ACCESS_KEY'], $hostname = $ossinfo['OSS_ENDPOINT'], $security_token = NULL);<br>     $bucket = $ossinfo['OSS_TEST_BUCKET'];<br>     $arr = array();<br>     foreach ($data as $v) {<br>         $picname = 'borrow-' . $borrow_id .'-'. time() . rand(111111, 999999).'.jpg';<br>         $arr[] = $picname;<br>         $object = 'images/'.$picname;<br>         $file_path = $_SERVER['DOCUMENT_ROOT'].$v;<br>         $res = $oss->upload_file_by_file($bucket, $object, $file_path, $options);<br>         Log::write('oss服务器返回信息========'.json_encode($res), Log::SQL);//查看调试信息<br>         if ($res->status != 200) {<br>             return false;<br>         }<br>     }<br>     $ossupdata = serialize($arr);<br>     $res = M("borrow_info")->where("id={$borrow_id}")->save(array('ossupdata' => $ossupdata));<br>     if($res){<br>         return true;<br>     }else{<br>         return false;<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