把站点的图片存储到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元