@@ -37,6 +37,7 @@ public function __construct($message, Exception $previous = null) {
3737}/*}}}*/
3838
3939class UpYun {
40+ public static $ VERSION = '1.1.1 ' ;
4041
4142/*{{{*/
4243 public static $ ED_AUTO = 'v0.api.upyun.com ' ;
@@ -46,12 +47,12 @@ class UpYun {
4647
4748 public static $ CONTENT_TYPE = 'Content-Type ' ;
4849 public static $ CONTENT_MD5 = 'Content-MD5 ' ;
49- public static $ CONTENT_SECRET = 'Content Secret ' ;
50+ public static $ CONTENT_SECRET = 'Content- Secret ' ;
5051
5152 // 缩略图
52- public static $ X_GMKERL_THUMBNAIL = 'x gmkerl thumbnail ' ;
53- public static $ X_GMKERL_TYPE = 'x gmkerl-type ' ;
54- public static $ X_GMKERL_VALUE = 'x gmkerl-value ' ;
53+ public static $ X_GMKERL_THUMBNAIL = 'x- gmkerl- thumbnail ' ;
54+ public static $ X_GMKERL_TYPE = 'x- gmkerl-type ' ;
55+ public static $ X_GMKERL_VALUE = 'x- gmkerl-value ' ;
5556 public static $ X_GMKERL_QUALITY = 'xgmkerl-quality ' ;
5657 public static $ X_GMKERL_UNSHARP = 'xgmkerl-unsharp ' ;
5758/*}}}*/
@@ -88,6 +89,13 @@ public function __construct($bucketname, $username, $password, $endpoint = NULL)
8889 $ this ->endpoint = is_null ($ endpoint ) ? self ::$ ED_AUTO : $ endpoint ;
8990 }/*}}}*/
9091
92+ /**
93+ * 获取当前SDK版本号
94+ */
95+ public function version () {
96+ return sels::$ VERSION ;
97+ }
98+
9199 /**
92100 * 创建目录
93101 * @param $path 路径
@@ -108,23 +116,34 @@ public function mkDir($path, $auto_mkdir = false) {/*{{{*/
108116 * @return boolean
109117 */
110118 public function delete ($ path ) {/*{{{*/
111- $ this ->_do_request ('DELETE ' , $ path );
119+ return $ this ->_do_request ('DELETE ' , $ path );
112120 }/*}}}*/
113121
114122
115123 /**
116124 * 上传文件
117- * @param $path 存储路径
118- * @param $file 需要上传的文件,可以是文件流或者文件内容
119- * @param $opts 可选参数
125+ * @param string $path 存储路径
126+ * @param boolean $auto_mkdir 自动创建目录
127+ * @param mixed $file 需要上传的文件,可以是文件流或者文件内容
128+ * @param array $opts 可选参数
120129 */
121- public function writeFile ($ path , $ file , $ opts = NULL ) {/*{{{*/
130+ public function writeFile ($ path , $ file , $ auto_mkdir = False , $ opts = NULL ) {/*{{{*/
131+ if (is_null ($ opts )) $ opts = array ();
122132 if (!is_null ($ this ->_content_md5 ) || !is_null ($ this ->_file_secret )) {
123- if (is_null ($ opts )) $ opts = array ();
124- if (!is_null ($ this ->_content_md5 )) array_push ($ opts , self ::$ CONTENT_MD5 . " {$ this ->_content_md5 }" );
125- if (!is_null ($ this ->_file_secret )) array_push ($ opts , self ::$ CONTENT_SECRET . " {$ this ->_file_secret }" );
133+ //if (!is_null($this->_content_md5)) array_push($opts, self::$CONTENT_MD5 . ": {$this->_content_md5}");
134+ //if (!is_null($this->_file_secret)) array_push($opts, self::$CONTENT_SECRET . ": {$this->_file_secret}");
135+ if (!is_null ($ this ->_content_md5 )) $ opts [self ::$ CONTENT_MD5 ] = $ this ->_content_md5 ;
136+ if (!is_null ($ this ->_file_secret )) $ opts [self ::$ CONTENT_SECRET ] = $ this ->_file_secret ;
126137 }
127138
139+ // 如果设置了缩略版本或者缩略图类型,则添加默认压缩质量和锐化参数
140+ //if (isset($opts[self::$X_GMKERL_THUMBNAIL]) || isset($opts[self::$X_GMKERL_TYPE])) {
141+ // if (!isset($opts[self::$X_GMKERL_QUALITY])) $opts[self::$X_GMKERL_QUALITY] = 95;
142+ // if (!isset($opts[self::$X_GMKERL_UNSHARP])) $opts[self::$X_GMKERL_UNSHARP] = 'true';
143+ //}
144+
145+ if ($ auto_mkdir === True ) $ opts ['Mkdir ' ] = 'true ' ;
146+
128147 return $ this ->_do_request ('PUT ' , $ path , $ opts , $ file );
129148 }/*}}}*/
130149
0 commit comments