mirror of
https://github.com/ufilesdk-dev/ufile-phpsdk.git
synced 2025-04-06 04:00:05 +08:00
新增head接口
This commit is contained in:
parent
0e4135d715
commit
1daed4cf76
21
v1/demo/head.php
Normal file
21
v1/demo/head.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once("../ucloud/proxy.php");
|
||||||
|
|
||||||
|
//存储空间名
|
||||||
|
$bucket = "your bucket";
|
||||||
|
//上传至存储空间后的文件名称(请不要和API公私钥混淆)
|
||||||
|
$key = "your key";
|
||||||
|
|
||||||
|
|
||||||
|
list($header, $data, $err) = UCloud_Head($bucket, $key);
|
||||||
|
if ($err) {
|
||||||
|
echo "error: " . $err->ErrMsg . "\n";
|
||||||
|
echo "code: " . $err->Code . "\n";
|
||||||
|
exit;
|
||||||
|
}else{
|
||||||
|
echo "code: " . 200 ."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
print_r($header);
|
||||||
|
echo "head $bucket/$key success\n";
|
@ -4,8 +4,8 @@ require_once("conf.php");
|
|||||||
require_once("utils.php");
|
require_once("utils.php");
|
||||||
require_once("digest.php");
|
require_once("digest.php");
|
||||||
|
|
||||||
|
$CURL_TIMEOUT=30;
|
||||||
// --------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------
|
||||||
|
|
||||||
class HTTP_Request
|
class HTTP_Request
|
||||||
{
|
{
|
||||||
public $URL;
|
public $URL;
|
||||||
@ -129,13 +129,16 @@ function UCloud_Client_Do($req)
|
|||||||
CURLOPT_TIMEOUT => $req->Timeout,
|
CURLOPT_TIMEOUT => $req->Timeout,
|
||||||
CURLOPT_CONNECTTIMEOUT => $req->Timeout
|
CURLOPT_CONNECTTIMEOUT => $req->Timeout
|
||||||
);
|
);
|
||||||
|
if($req->METHOD =="HEAD"){
|
||||||
|
$options[CURLOPT_NOBODY]=true;
|
||||||
|
}
|
||||||
if($req->EncodedQuery() !== ""){
|
if($req->EncodedQuery() !== ""){
|
||||||
$options[CURLOPT_URL] = $url['host'] . "/" . $url['path'] . "?" . $req->EncodedQuery();
|
$options[CURLOPT_URL] = $url['host'] . "/" . $url['path'] . "?" . $req->EncodedQuery();
|
||||||
}else{
|
}else{
|
||||||
$options[CURLOPT_URL] = $url['host'] . "/" . $url['path'];
|
$options[CURLOPT_URL] = $url['host'] . "/" . $url['path'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$httpHeader = $req->Header;
|
$httpHeader = $req->Header;
|
||||||
if (!empty($httpHeader))
|
if (!empty($httpHeader))
|
||||||
{
|
{
|
||||||
@ -151,7 +154,9 @@ function UCloud_Client_Do($req)
|
|||||||
} else {
|
} else {
|
||||||
$options[CURLOPT_POSTFIELDS] = "";
|
$options[CURLOPT_POSTFIELDS] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt_array($ch, $options);
|
curl_setopt_array($ch, $options);
|
||||||
|
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
$ret = curl_errno($ch);
|
$ret = curl_errno($ch);
|
||||||
if ($ret !== 0) {
|
if ($ret !== 0) {
|
||||||
@ -159,6 +164,7 @@ function UCloud_Client_Do($req)
|
|||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
return array(null, $err);
|
return array(null, $err);
|
||||||
}
|
}
|
||||||
|
|
||||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
@ -258,6 +264,7 @@ function UCloud_Client_Ret($resp)
|
|||||||
}else{
|
}else{
|
||||||
$data['ETag'] = UCloud_Header_Get($resp->Header, 'Etag');
|
$data['ETag'] = UCloud_Header_Get($resp->Header, 'Etag');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (floor($code/100) == 2) {
|
if (floor($code/100) == 2) {
|
||||||
return array($data, null);
|
return array($data, null);
|
||||||
}
|
}
|
||||||
@ -274,6 +281,33 @@ function UCloud_Client_Call($self, $req, $type = HEAD_FIELD_CHECK)
|
|||||||
return UCloud_Client_Ret($resp);
|
return UCloud_Client_Ret($resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@results: ($header,$data, $error)
|
||||||
|
function UCloud_Client_Call_ReHeader($self, $req, $type = HEAD_FIELD_CHECK)
|
||||||
|
{
|
||||||
|
list($resp, $err) = $self->RoundTrip($req, $type);
|
||||||
|
if ($err !== null) {
|
||||||
|
return array(null, null, $err);
|
||||||
|
}
|
||||||
|
|
||||||
|
$code = $resp->StatusCode;
|
||||||
|
$data = null;
|
||||||
|
if ($code >= 200 && $code <= 299) {
|
||||||
|
if ($resp->ContentLength !== 0 && UCloud_Header_Get($resp->Header, 'Content-Type') == 'application/json') {
|
||||||
|
$data = json_decode($resp->Body, true);
|
||||||
|
if ($data === null) {
|
||||||
|
$err = new UCloud_Error($code, 0, "");
|
||||||
|
return array($resp->Header, null, $err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (floor($code/100) == 2) {
|
||||||
|
return array($resp->Header, $data, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array($resp->Header, $data, UCloud_ResponseError($resp));
|
||||||
|
}
|
||||||
|
|
||||||
//@results: $error
|
//@results: $error
|
||||||
function UCloud_Client_CallNoRet($self, $req, $type = HEAD_FIELD_CHECK)
|
function UCloud_Client_CallNoRet($self, $req, $type = HEAD_FIELD_CHECK)
|
||||||
{
|
{
|
||||||
|
@ -272,6 +272,27 @@ function UCloud_Delete($bucket, $key)
|
|||||||
return UCloud_Client_Call($client, $req);
|
return UCloud_Client_Call($client, $req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------Head文件------------------------------
|
||||||
|
function UCloud_Head($bucket, $key)
|
||||||
|
{
|
||||||
|
|
||||||
|
$err = CheckConfig(ActionType::HEAD);
|
||||||
|
if ($err != null) {
|
||||||
|
return array(null, $err);
|
||||||
|
}
|
||||||
|
|
||||||
|
global $UCLOUD_PROXY_SUFFIX;
|
||||||
|
$host = $bucket . $UCLOUD_PROXY_SUFFIX;
|
||||||
|
$path = "$key";
|
||||||
|
|
||||||
|
$req = new HTTP_Request('HEAD', array('host'=>$host, 'path'=>$path), null, $bucket, $key);
|
||||||
|
$req->Header['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||||
|
|
||||||
|
$client = new UCloud_AuthHttpClient(null);
|
||||||
|
return UCloud_Client_Call_ReHeader($client, $req);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------追加上传------------------------------
|
//------------------------------追加上传------------------------------
|
||||||
function UCloud_AppendFile($bucket, $key, $file, $position)
|
function UCloud_AppendFile($bucket, $key, $file, $position)
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,7 @@ abstract class ActionType
|
|||||||
const GETFILE = 8;
|
const GETFILE = 8;
|
||||||
const APPENDFILE = 9;
|
const APPENDFILE = 9;
|
||||||
const LISTOBJECTS = 10;
|
const LISTOBJECTS = 10;
|
||||||
|
const HEAD = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
class UCloud_Error
|
class UCloud_Error
|
||||||
@ -127,6 +128,7 @@ function CheckConfig($action) {
|
|||||||
case ActionType::DELETE:
|
case ActionType::DELETE:
|
||||||
case ActionType::UPLOADHIT:
|
case ActionType::UPLOADHIT:
|
||||||
case ActionType::LISTOBJECTS:
|
case ActionType::LISTOBJECTS:
|
||||||
|
case ActionType::HEAD:
|
||||||
if ($UCLOUD_PROXY_SUFFIX == "") {
|
if ($UCLOUD_PROXY_SUFFIX == "") {
|
||||||
return new UCloud_Error(400, -1, "no proxy suffix found in config");
|
return new UCloud_Error(400, -1, "no proxy suffix found in config");
|
||||||
} else if ($UCLOUD_PUBLIC_KEY == "" || strstr($UCLOUD_PUBLIC_KEY, " ") != FALSE) {
|
} else if ($UCLOUD_PUBLIC_KEY == "" || strstr($UCLOUD_PUBLIC_KEY, " ") != FALSE) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user