定义常量
//以下请填写 define('access_id',''); define('access_key',''); define('hostname','oss-cn-hangzhou.aliyuncs.com');// 这里要写清楚 define('bucket','zyqc'); 函数代码(加到项目函数中) /* $data string 要上传的图片 */ function upload_file_oss($data) { $access_id=access_id; $access_key=access_key; $hostname=hostname; $bucket=bucket; import("Org.Alioss.alioss"); $oss = new ALIOSS($access_id,$access_key, $hostname, $security_token = NULL); //要上传的文件服务器地址 $file_path = $_SERVER['DOCUMENT_ROOT'].__ROOT__.'/'.$data; $res = $oss->upload_file_by_file($bucket, $data, $file_path); $array=(array)$res; switch ($array['status']) { case '200': return true; break; default: return false; break; } }
用法
upload_file_oss('Upload/test.jpg');
附件(上传至Library/Org)