针对阿里kissy编辑器上传图片到阿里云oss存储服务器代码
直接上干货 public function index()<br>
{<br>
$this->savePathNew = C('ADMIN_UPLOAD_DIR').'Article/' ;<br>
$this->saveRule = date("YmdHis",time());<br>
$info = $this->CUpload();<br>
$image_url = $info[0]['savepath'].$info[0]['savename'];<br>
//上传成功<br>
if($image_url){<br>
$returnul = $this->upload_file_to_alioss($image_url);<br>
if($returnul){<br>
echo '{"status": "0", "imgUrl": "' .$returnul. '"}';<br>
}else{<br>
echo '{"status": "1", "error": "'.$info['info'].'"}';<br>
}<br>
//echo '{"status": "0", "imgUrl": "' .__APP__."/".$image_url. '"}';<br>
}else{<br>
echo '{"status": "1", "error": "'.$info['info'].'"}';<br>
}<br>
}<br>
<br>
//uploader 插件上传图片到oss<br>
function upload_file_to_alioss($image_url)<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>
$picname = 'borrow-borrow_info-'. time() . rand(111111, 999999).'.jpg';<br>
$object = 'images/uploads/'.$picname;<br>
$file_path = DOCUMENT_ROOT.'/'.$image_url;<br>
$options = array();<br>
$res = $oss->upload_file_by_file($bucket, $object, $file_path, $options);<br>
Log::write('image_url======'.json_encode($res), Log::SQL);//查看调试信息<br>
if ($res->status != 200) {<br>
return false;<br>
}else{<br>
Log::write('远程url链接======'.$ossinfo['OOS_MYPOINT'].$object, Log::SQL);<br>
return $ossinfo['OOS_MYPOINT'].$object;<br>
}<br>
}
AD:真正免费,域名+虚机+企业邮箱=0元