最近用到了又拍云,但是今天遇到个对接问题,宝塔很老版本的环境下,测试没有问题,用新版本宝塔搭建环境后,出现不兼容问题,用的官方测试问题:
老版本宝塔一路升级上来,没问题,测试链接:http://c.ggxzw.com/rest_upload.php,显示200,说明上传成功
新版本搭建完后,有问题,显示:0,说明有问题,链接:http://xs.ynmrw.com/rest_upload.php
服务器可以正常ping通又拍,而且直接在执行语句可以正常上传,说明可以正常连通。
服务器环境:linux+php 5.6 7.2等全都测试,还是显示错误
请问如何处理
rest_upload.php由又拍云官方提供,代码如下:
- <?php
- //Rest Api Upload Demo
- class upyun{
- const END_POINT = "http://v0.api.upyun.com";
- private $bucketname;
- private $username;
- private $password;
- private $ctimeout;
- public function __construct($bucketname, $username, $password, $ctimeout){
- $this->bucketname = $bucketname;
- $this->username = $username;
- $this->password = $password;
- $this->ctimeout = $ctimeout;
- }
- public function restupload($localpath, $savepath){
- $uri = "/{$this->bucketname}$savepath";
- $date = gmdate('D, d M Y H:i:s \G\M\T');
- $fsize = filesize($localpath);
- $signature = base64_encode(hash_hmac("sha1", "PUT&$uri&$date", md5("{$this->password}"), true));
- $header = array("Content-Length:$fsize", "Authorization:UPYUN {$this->username}:$signature", "Date:$date");
- $fh = fopen($localpath,'rb');
- $ch = curl_init(self::END_POINT.$uri);
- curl_setopt($ch, CURLOPT_INFILE, $fh);
- curl_setopt($ch, CURLOPT_INFILESIZE, $fsize);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_TIMEOUT, "{$this->ctimeout}");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_exec($ch);
- $rsp_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- echo $rsp_code;
- }
- }
- $upyun = new upyun("服务名", "操作员账号", "操作员密码", 3600);
- $upyun->restupload("13.jpg", "/999.jpg");
- ?>
复制代码
|
|