Qiniu Resource (Cloud) Storage SDK for PHP

Related tags

API php-sdk
Overview

Qiniu Cloud SDK for PHP

Software License Build Status GitHub release Latest Stable Version Total Downloads Scrutinizer Code Quality Coverage Status Join Chat @qiniu on weibo

安装

  • 推荐使用 composer 进行安装。可以使用 composer.json 声明依赖,或者运行下面的命令。SDK 包已经放到这里 qiniu/php-sdk
$ composer require qiniu/php-sdk
  • 直接下载安装,SDK 没有依赖其他第三方库,但需要参照 composer 的 autoloader,增加一个自己的 autoloader 程序。

运行环境

Qiniu SDK版本 PHP 版本
7.x cURL extension, 5.3 - 5.6,7.0
6.x cURL extension, 5.2 - 5.6

使用方法

上传

use Qiniu\Storage\UploadManager;
use Qiniu\Auth;
...
    $uploadMgr = new UploadManager();
    $auth = new Auth($accessKey, $secretKey);
    $token = $auth->uploadToken($bucket);
    list($ret, $error) = $uploadMgr->putFile($token, 'key', 'filePath');
...

测试

$ ./vendor/bin/phpunit tests/Qiniu/Tests/

常见问题

  • $error 保留了请求响应的信息,失败情况下 retnone, 将 $error 可以打印出来,提交给我们。
  • API 的使用 demo 可以参考 examples

代码贡献

详情参考代码提交指南

贡献记录

联系我们

  • 如果需要帮助,请提交工单(在portal右侧点击咨询和建议提交工单,或者直接向 [email protected] 发送邮件)
  • 如果有什么问题,可以到问答社区提问,问答社区
  • 更详细的文档,见官方文档站
  • 如果发现了 bug, 欢迎提交 issue
  • 如果有功能需求,欢迎提交 issue
  • 如果要提交代码,欢迎提交 pull request
  • 欢迎关注我们的微信 微博,及时获取动态信息。

代码许可

The MIT License (MIT).详情见 License文件.

Comments
  • 批量操作资源时,返回no such bucket错误信息

    批量操作资源时,返回no such bucket错误信息

    Laravel 5.5 composer.json "qiniu/php-sdk": "^7.2",

    $param = BucketManager::buildBatchMove(DEV_BUCKET, $key_pairs, PRODUCT_BUCKET, true);
    $auth = new Auth(ACCESS_KEY, SECRET_KEY);
    $bucket_Manager = new BucketManager($auth);
    list($response, $error) = $bucket_Manager->batch($param);
    

    其中运行时

    $url = 'http://rs.qiniu.com/batch';
    $body = "op=/move/ZGV2ZWxvcC1yZXNvdXJjZS1jb250ZW50/ZGV2ZWxvcC1yZXNvdXJjZS1jb250ZW50OmRhc2QuanBn/force/true&op=/move/ZGV2ZWxvcC1yZXNvdXJjZS1jb250ZW50OjE=/ZGV2ZWxvcC1yZXNvdXJjZS1jb250ZW50OmRhc2QuanBn/force/true&op=/move/ZGV2ZWxvcC1yZXNvdXJjZS1jb250ZW50/YXBwLXJlc291cmNlLWNvbnRlbnQ6ZGFzZC5qcGc=/force/true"
    

    返回的结果是

    response null
    error
    Response {
      +statusCode: 631
      +headers: array:7 [
        "Server" => "nginx"
        "Date" => "Tue, 31 Oct 2017 09"
        "Content-Type" => "application/json"
        "Content-Length" => "26"
        "Connection" => "keep-alive"
        "X-Log" => "TBLMGR"
        "X-Reqid" => "tmQAAB5lR-Y5n_IU"
      ]
      +body: "{"error":"no such bucket"}"
      +error: "no such bucket"
      -jsonData: array:1 [
        "error" => "no such bucket"
      ]
      +duration: 0.036
    }
    

    已确认DEV_BUCKETPRODUCT_BUCKET都是同一个名称,因为没建第二个bucket,用的统一个库,然后ACCESS_KEY,SECRET_KEY也没问题 但是会报这个no such bucket问题,请问是什么原因

    opened by lliudb 11
  • PHP 7.2.3 中报错

    PHP 7.2.3 中报错

    $accessKey = env('Qiniu_Ak');
    $secretKey = env('Qiniu_SK');
    $bucket = env('Qiniu_Bucket');
    $auth = new \Qiniu\Auth($accessKey, $secretKey);
    // 生成上传Token
    $token = $auth->uploadToken($bucket);
    // 构建 UploadManager 对象
    $uploadMgr = new \Qiniu\Storage\UploadManager();
    // 要上传文件的本地路径
    $filePath = $_FILES['img']['tmp_name'];
    // 上传到七牛后保存的文件名
    $key = 'abc.jpg';
    // 调用 UploadManager 的 putFile 方法进行文件的上传。
    list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
    

    Trying to get property 'srcUpHosts' of non-object

    in Config.php (line 42) at HandleExceptions->handleError(8, 'Trying to get property 'srcUpHosts' of non-object', '/home/www/lshop/vendor/qiniu/php-sdk/src/Qiniu/Config.php', 42, array('accessKey' => '', 'bucket' => '1', 'zone' => array(null, object(Error)), 'scheme' => 'http://'))in Config.php (line 42) at Config->getUpHost('', '1')in FormUploader.php (line 58) at FormUploader::put(':W4QCPg8wEImFT1DIb0Bnw1AU_ik=:eyJzY29wZSI6IjEiLCJkZWFkbGluZSI6MTUyMjM4NzczNH0=', 'abc.jpg',

    opened by swq8 9
  • 不适用autoload 会提示functions.php中的方法不存在

    不适用autoload 会提示functions.php中的方法不存在

    框架使用的TP5 use Qiniu\Storage\UploadManager; use Qiniu\Auth; use Qiniu\Storage\BucketManager; 使用的命名空间

    $upManager = new UploadManager(); $auth = new Auth(Config::get('Qiniu.accessKey'), Config::get('Qiniu.secretKey')); $token = $auth->uploadToken(Config::get('Qiniu.bucket')); list($ret, $error) = $upManager->put($token, $info->getFilename(), $info->getSaveName()); if ($err !== null) { unlink($info->getSaveName()); }else{ unlink($info->getSaveName());//删除本地服务器的图片 $hisImg = Db::name('user')->where(array('id'=>$uid))->value('user_img'); $auth = new Auth(Config::get('Qiniu.accessKey'), Config::get('Qiniu.secretKey')); $bucketMgr = new BucketManager($auth); if ($hisImg) { $bucketMgr->delete(Config::get('Qiniu.bucket'), $hisImg); } $res = Db::name('user')->where(array('id'=>$uid))->setField('user_img',$info->getFilename()); if($res) { $arr = array('code'=>'ok','msg'=>'上传成功','cover'=>'http://o6wndwjxn.qnssl.com/'.$info->getFilename()); }else{ $bucketMgr->delete(Config::get('Qiniu.bucket'), $info->getFilename()); $arr = array('code'=>'fail','msg'=>'上传失败'); } } 传至七牛的代码

    opened by gzxy-0102 9
  • 兼容php8.1和php8.2

    兼容php8.1和php8.2

    不影响低版本PHP!!!

    • \src\Qiniu\Http\Header.php > During inheritance of ArrayAccess
    • \src\Qiniu\Config.php > Creation of dynamic property Qiniu\Config::$zone is deprecated
    • \src\Qiniu\Auth.php > strlen(): Passing null to parameter #1 ($string) of type string is deprecated
    enhancement size/S 
    opened by tianyiw2013 8
  • Zone::queryZone 方法返回错误

    Zone::queryZone 方法返回错误

    如果bucket或者ak参数错误,Zone::queryZone方法会返回return array(null, new Error($url, $ret));数组

    config.php 第42行 调用了$zone->srcUpHosts[0] ,导致报错 PHP Notice: Trying to get property of non-object

    opened by mrwzq 7
  • 分片上传的版本号使用枚举判断,并添加单元测试覆盖错误版本号

    分片上传的版本号使用枚举判断,并添加单元测试覆盖错误版本号

    • 新增 myclabs/php-enum
    • 新增枚举类 SplitUploadVersion
    • 新增错误版本号 v, 1, 2 的单元测试

    另外有几个注意点 Reviewers 可以看下:

    1. ~~枚举类 SplitUploadVersion 按照当前项目风格(一个类一个文件),在 src/Qiniu/Storage/ResumeUploader.php 这个路径下。从分类的角度上看,与同级目录有点格格不入的感觉,不知有没有更好的建议;~~ 更改放入 src/Qiniu/Enum/
    2. 在枚举类的加持下 ResumeUploader->version 若不合法就该类构造不出来,即 ResumeUploader->version 在运行时是安全的。但由于个人便好,仍在该类的方法中冗余了一部分判断逻辑来兜底。若觉得不必要可删除该部分代码。
      if ($this->version == SplitUploadVersion::V1) {
          // ...
      } elseif ($this->version == SplitUploadVersion::V2) {
          // ...
      } else { // 冗余的 `else`
          throw new \Exception("only support v1/v2 now!");
      }
      
    size/L 
    opened by lihsai0 6
  • PHP7.2.11 出现 Trying to get property 'srcUpHosts' of non-object

    PHP7.2.11 出现 Trying to get property 'srcUpHosts' of non-object

    错误信息: Trying to get property 'srcUpHosts' of non-object at /vendor/qiniu/php-sdk/src/Qiniu/Config.php:45

    Qiniu\Http\Client::sendRequest 请求接口 https://api.qiniu.com/v2/query?ak=ak&bucket=bucket 时,未响应正确数据,个人编写 curl 代码在相同环境下数据响应正常, 代码如下:

    $url = 'https://api.qiniu.com/v2/query?ak=&bucket=';
    
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); 
    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
    $output = curl_exec($ch);
    curl_close($ch);
    
    var_dump($output);
    

    类似问题: #265 #254

    opened by moell-peng 6
  • 关于header 名称大小写问题

    关于header 名称大小写问题

    php 7.0.7 sdk 7.2.2 os osx 10.11.2

    https://github.com/qiniu/php-sdk/blob/34aba14b94cce7715b241a2204658f9da63f839c/src/Qiniu/Http/Client.php#L118

    不同环境下header内容如下

    浏览器环境下

    HTTP/1.1 200 OK
    connection: keep-alive
    content-length: 1309
    content-type: application/json
    date: Fri, 19 Jan 2018 06:43:57 GMT
    server: openresty
    x-log: RSF:2;RSF:4;ZONEPROXY:186
    x-reqid: VDQAAKwPRqwMIwsV
    x-via: vdn-hnhy-tel-1-2,xs632
    
    

    cli环境下

    HTTP/1.1 200 OK
    Server: openresty
    Date: Fri, 19 Jan 2018 06:43:57 GMT
    Content-Type: application/json
    Content-Length: 1309
    Connection: keep-alive
    X-Log: RSF:2;RSF:4;ZONEPROXY:155
    X-Reqid: VDQAAK1HDuIMIwsV
    X-Via: vdn-hnhy-tel-1-2,xs99
    

    这将导致后续 Qiniu\Http\Response::isJson 调用失败

    strpos($headers['Content-Type'], 'application/json') === 0;
    
    opened by tim0991 6
  • 关于上传文件打印字符串问题

    关于上传文件打印字符串问题

    文件地址: vendor/qiniu/php-sdk/src/Qiniu/Config.php 代码关键词:getZone

    private function getZone($accessKey, $bucket)
        {
            $cacheId = "$accessKey:$bucket";
    
            if (isset($this->zoneCache[$cacheId])) {
                // print("from cache\n");
                $zone = $this->zoneCache[$cacheId];
            } elseif (isset($this->zone)) {
                // print("from set\n");
                $zone = $this->zone;
                $this->zoneCache[$cacheId] = $zone;
            } else {
                // print("from query\n");
                $zone = Zone::queryZone($accessKey, $bucket);
                $this->zoneCache[$cacheId] = $zone;
            }
            return $zone;
        }
    

    注释的打印代码

    opened by jasonjiang123 6
  • 获取空间域名失败

    获取空间域名失败

    使用java-java可以成功获取,但是使用php-sdk就返回空集合。以下是使用抓包工具包获取的请求信息。

    GET /v6/domain/list?tble=temp HTTP/1.1 Host: api.qiniu.com User-Agent: QiniuPHP/7.1.3 (Windows NT/i586) PHP/5.4.45 Accept: / Authorization: QBox 6utdCVaQ_E_4_74ydeKYAjQygXNMnu-9KP0QC14p:mcIPQC71PsD40hrM9H8DY2jvPF8=

    HTTP/1.1 200 OK Server: nginx Date: Mon, 14 Aug 2017 05:39:12 GMT Content-Type: application/json Content-Length: 2 Connection: keep-alive X-Log: ONE:1;APIS:8 X-Reqid: VQUAAA95j6zSn9oU X-Reqid: VQUAAA95j6zSn9oU

    []

    opened by Jamling 6
  • 服务器接收到的回调请求头中没有HTTP_AUTHORIZATION

    服务器接收到的回调请求头中没有HTTP_AUTHORIZATION

    $_SERVER数组中没有HTTP_AUTHORIZATION索引, 有一个HTTP_X_REQID file_get_contents('php://input')能获取成功

    // 服务器callback.php 代码
    $content = var_export($_SERVER, true);
    file_put_contents('notify', $content);
    
    opened by cloudsthere 6
  • SDK里面的注释变量类型能否补全?

    SDK里面的注释变量类型能否补全?

    如:vendor/qiniu/php-sdk/src/Qiniu/Storage/UploadManager.php 里面的put方法 反而下面putFile的注释类型是完整

    /**
         * 上传二进制流到七牛
         *
         * @param $upToken    上传凭证
         * @param $key        上传文件名
         * @param $data       上传二进制流
         * @param $params     自定义变量,规格参考
         *                    http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar
         * @param $mime       上传数据的mimeType
         * @param $checkCrc   是否校验crc32
         *
         * @return array    包含已上传文件的信息,类似:
         *                                              [
         *                                                  "hash" => "<Hash string>",
         *                                                  "key" => "<Key string>"
         *                                              ]
         */
    
    opened by season886 0
  • 在php8.1下 回报During inheritance of ArrayAccess错误

    在php8.1下 回报During inheritance of ArrayAccess错误

    报错信息: During inheritance of ArrayAccess: Uncaught think\exception\ErrorException: Return type of Qiniu\Http\Header::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .../vendor/qiniu/php-sdk/src/Qiniu/Http/Header.php:114

    question 
    opened by HighSpecific 8
  • composer安装失败

    composer安装失败

    • Root composer.json requires qiniu/php-sdk ^7.5 -> satisfiable by qiniu/php-sdk[v7.5.0].
      • qiniu/php-sdk v7.5.0 requires myclabs/php-enum 1.6.6 -> found myclabs/php-enum[1.6.6] but the package is fixed to 1.7.7 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    opened by ideaviewes 5
Releases(v7.8.0)
Owner
Qiniu Cloud
Connect Data, Redefine Value.
Qiniu Cloud
Supermeteor is PHP SDK use to create cloud message: whatsapp, sms and email etc

Supermeteor Supermeteor is PHP SDK use to create cloud message: whatsapp, sms and email etc How to use install using composer composer require superme

null 0 Jul 15, 2022
Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs

Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps to access the API in an object-oriented way.

Thuong Le 77 Dec 19, 2022
Zoho CRM API SDK is a wrapper to Zoho CRM APIs. By using this sdk, user can build the application with ease

Archival Notice: This SDK is archived. You can continue to use it, but no new features or support requests will be accepted. For the new version, refe

null 81 Nov 4, 2022
Quickly and easily expose Doctrine entities as REST resource endpoints with the use of simple configuration with annotations, yaml, json or a PHP array.

Drest Dress up doctrine entities and expose them as REST resources This library allows you to quickly annotate your doctrine entities into restful res

Lee Davis 88 Nov 5, 2022
Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application

CORS Middleware for Laravel Implements https://github.com/asm89/stack-cors for Laravel About The laravel-cors package allows you to send Cross-Origin

Fruitcake 6.2k Jan 8, 2023
CORS (Cross-Origin Resource Sharing) for your Symfony/Laravel requests

CORS for PHP (using the Symfony HttpFoundation) Library and middleware enabling cross-origin resource sharing for your http-{foundation,kernel} using

Fruitcake 91 Dec 22, 2022
A Symfony bundle that provides #StandWithUkraine banner and has some built-in features to block access to your resource for Russian-speaking users.

StandWithUkraineBundle На русском? Смотри README.ru.md This bundle provides a built-in StandWithUkraine banner for your Symfony application and has so

Victor Bocharsky 10 Nov 12, 2022
This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.

The first PHP API to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

NETFLIE 135 Dec 29, 2022
Appwrite configuration for Cloud Function runtimes settings 🌩

Appwrite Runtimes Appwrite repository for Cloud Function runtimes that contains the configurations and tests for all of the Appwrite runtime environme

Appwrite 39 Nov 22, 2022
The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructure and leverage the power of 1Password Secrets Automation

1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructu

Michelangelo van Dam 12 Dec 26, 2022
Facebook SDK for PHP (v6) - allows you to access the Facebook Platform from your PHP app

Facebook SDK for PHP (v6) This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app. Installa

null 0 Aug 10, 2022
Unofficial Firebase Admin SDK for PHP

Firebase Admin PHP SDK Table of Contents Overview Installation Documentation Support License Overview Firebase provides the tools and infrastructure y

kreait 1.9k Jan 3, 2023
Notion PHP SDK

Notion PHP SDK This is an unofficial PHP SDK for the new public Notion API. It's work in progress as we didn't get the change to be included to the pr

Codecycler 43 Nov 29, 2022
爱发电非官方简易 PHP SDK

afdian-php-sdk 爱发电非官方简易 PHP SDK by Akkariin 这是一个简单的 SDK,可以用于查询爱发电的订单和赞助者信息 Installation 将项目 clone 到本地即可 git clone https://github.com/ZeroDream-CN/afdi

ZeroDream-CN 17 Nov 7, 2022
AWS Cognito package using the AWS SDK for PHP/Laravel

Laravel Package to manage Web and API authentication with AWS Cognito AWS Cognito package using the AWS SDK for PHP This package provides a simple way

EllaiSys 74 Nov 15, 2022
PHP SDK to interact with the Casper Network nodes via RPC

casper-php-sdk PHP SDK to interact with Casper Network nodes via RPC Install composer require make-software/casper-php-sdk Examples RPC Client: $node

MAKE Technology LLC 7 May 8, 2022
A Laravel 5+ (and 4) service provider for the AWS SDK for PHP

AWS Service Provider for Laravel 5/6/7/8 This is a simple Laravel service provider for making it easy to include the official AWS SDK for PHP in your

Amazon Web Services 1.5k Dec 28, 2022
A complete Notion SDK for PHP developers.

notion-sdk-php A complete Notion SDK for PHP developers. Installation composer require mariosimao/notion-php Getting started A Notion token will be n

Mario Simão 77 Nov 29, 2022
SDK of the LINE Login API for PHP

LINE Login for PHP SDK of the LINE Login API for PHP Documentation See the official API documentation for more information. Installation Use the packa

null 4 Sep 15, 2022