basePath.'/..'."/lib/core/ucloud/ucloud/proxy.php"); require_once(Yii::app()->basePath.'/..'."/protected/config/ucloud_".YII_ENV."_conf.php"); class Ucloud { //存储空间名 public $bucket; public $image_domain; public function __construct() { global $BUCKET; global $IMAGE_DOMAIN; $this->bucket = $BUCKET; $this->image_domain = $IMAGE_DOMAIN; } /** * 上传文件 * @param $key 上传至存储空间后的文件名称(请不要和API公私钥混淆) * @param $file 待上传文件的本地路径 * @return array */ public function putFile($key,$file){ $result = array( 'status' => 0, 'msg' => '', 'data' => '', ); //该接口适用于0-10MB小文件,更大的文件建议使用分片上传接口 list($data, $err) = UCloud_PutFile($this->bucket, $key, $file); if ($err) { $result['msg'] = $err->ErrMsg; }else{ $result['status'] = 1; $result['data'] = $data['ETag']; } return $result; } /** * 获取文件 * @param $key * @param bool $isPrivate * @return array|string */ public function getFileUrl($key,$isPrivate = false){ if($isPrivate){ //访问私有Bucket的例子 $url = UCloud_MakePrivateUrl($this->bucket, $key); }else{ //访问公有Bucket的例子 $url = UCloud_MakePublicUrl($this->bucket, $key); } return $url; } /** * 删除文件 * @param $key * @return array */ public function deleteFile($key){ $result = array( 'status' => 0, 'msg' => '', 'data' => '', ); list($data, $err) = UCloud_Delete($this->bucket, $key); if ($err) { $result['msg'] = $err->ErrMsg; }else{ $result['status'] = 1; $result['data'] = ''; $result['msg'] = "delete $this->bucket/$key success"; } return $result; } } //$ucloud = new Ucloud(); //$key = "test.png"; //$file = "e:/1.png"; ////$rs = $ucloud->putFile(); // //$url = $ucloud->getFileUrl($key); //var_dump($url);die; //$key = "/test/test.png"; //$bool = $ucloud->deleteFile($key); // //var_dump($bool);die;