You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

48 lines
1.6 KiB

<?php
namespace App\Common\Utils;
class Utils
{
/**
* 模拟发送PUT方式请求
* @param $url
* @param $contentBase64Md5
* @param $fileContent
* @return mixed|string
* @author Ayz
*/
public static function sendHttpPUT($url, $contentBase64Md5, $fileContent)
{
$header = [
'Content-Type:application/octet-stream'
];
$status = '';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_FILETIME, true);
curl_setopt($curl_handle, CURLOPT_FRESH_CONNECT, false);
curl_setopt($curl_handle, CURLOPT_HEADER, true); // 输出HTTP头 true
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 5184000);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $fileContent);
$result = curl_exec($curl_handle);
$status = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
if ($result === false) {
$status = curl_errno($curl_handle);
$result = 'put file to oss - curl error :' . curl_error($curl_handle);
}
curl_close($curl_handle);
//$this->debug($url, $fileContent, $header, $result);
return $status;
}
}