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文件.

Issues
  • Zone缓存文件这个路径,通常的配置应该是没有写入权限的

    Zone缓存文件这个路径,通常的配置应该是没有写入权限的

    private function hostCacheFilePath()
    {
        $home = getenv('HOME');
        return $home . '/.qiniu_phpsdk_hostscache.json';
    }
    
    opened by mortyu 13
  • 批量操作资源时,返回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
  • 不适用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
  • 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 alex-888 9
  • 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
  • 重新转码

    重新转码

    语音上传之后,显示转码失败,多次重新上传后,还是转码失败。相同的语音文件,换一台电脑上传就会成功

    opened by jackyang1984 7
  • 请问为什么没有命名空间呢?

    请问为什么没有命名空间呢?

    没有命名空间,用 composer 安装后,使用不方便呀。请问可以添加命名空间么?

    opened by blankhua 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
  • 添加图片处理链接统一拼接方法

    添加图片处理链接统一拼接方法

    统一拼接链接方法,函数中也添加了相应的方法,方便使用。

    opened by SherlockRen 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
  • make header key initial capital

    make header key initial capital

    fix #371

    同时:

    • 修复 header 解析错误
    • 新增通过大小写不敏感的名字获取 header 的方式,新增 response->normalizedHeader

    以下为之前 header 解析错误的例子:

    :status: 200 被解析为 "" -> "status"

    origin: https://www.qiniu.com 被解析为 "Origin" -> "https"

    last-modified: Mon, 06 Sep 2021 06:44:52 GMT 被解析为 "Last-Modified" -> "Mon, 06 Sep 2021 06"

    size/L 
    opened by lihsai0 3
  • Response::isJson() 实现问题

    Response::isJson() 实现问题

    https://github.com/qiniu/php-sdk/blob/master/src/Qiniu/Http/Response.php#L183

    此处只要满足 array_key_exists('content-type', $headers) 即返回 true,看起来不太合理

    opened by 71sprite 2
  • 分片上传,为什么 ResumeUploader.php 里为什么只暴露了一个 upload 方法呢?

    分片上传,为什么 ResumeUploader.php 里为什么只暴露了一个 upload 方法呢?

    分片上传的需求,不应该是服务器有了整个文件以后,调用这个方法一起执行的,而是可以乱序的单独上传分片之后,自行调用 completeParts 方法来完成上传的,因此建议 public 相关方法,或者单独提供一个分片上传的其他解决方案。

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

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

    • 新增 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 2
  • Add curl options CURLOPT_TIMEOUT

    Add curl options CURLOPT_TIMEOUT

    size/M 
    opened by sunquakes 1
  • Fixed error file prefetching link comment

    Fixed error file prefetching link comment

    fixed Error file prefetching link comment.

    size/XS 
    opened by curder 0
  • Update Region.php

    Update Region.php

    获取 Region 的时候 如果返回错误 return 的是一个array 里面包含Error 但是上层调用的时候没有做处理,导致报错,并且错误信息并不能描述出问题出在哪里。

    //vendor/qiniu/php-sdk/src/Qiniu/Config.php
    private function getRegion($accessKey, $bucket)
        {
            $cacheId = "$accessKey:$bucket";
    
            if (isset($this->regionCache[$cacheId])) {
                $region = $this->regionCache[$cacheId];
            } elseif (isset($this->zone)) {
                $region = $this->zone;
                $this->regionCache[$cacheId] = $region;
            } else {
                /*******这里处理的时候没有考虑到异常的情况,所以$region 是一个数组, 上层调用的时候会报错***/
                $region = Zone::queryZone($accessKey, $bucket);
                $this->regionCache[$cacheId] = $region;
            }
            return $region;
        }
    
    size/XS 
    opened by kingofzihua 0
  • Feature

    Feature

    增加获取 bucket 存储空间方法getSpaceData

    opened by wuliang9524 0
  • Develop

    Develop

    size/M 
    opened by ankadada 1
Releases(v7.4.1)
Owner
Qiniu Cloud
Connect Data, Redefine Value.
Qiniu Cloud
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 40 Dec 22, 2021
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 79 Dec 30, 2021
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 84 Nov 20, 2021
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 5.9k Jan 12, 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 20 Jan 11, 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 8 Sep 16, 2021
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.7k Jan 20, 2022
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 22 Jan 4, 2022
爱发电非官方简易 PHP SDK

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

ZeroDream-CN 10 Jan 12, 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 33 Jan 20, 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 6 Dec 21, 2021
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.4k Jan 14, 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 39 Jan 11, 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 2 Nov 3, 2021
PHP SDK - Flexie CRM fiskalizimi solution

PHP SDK - Flexie CRM fiskalizimi solution Fiskalizimi PHP SDK allows you to talk and generate your e-invoices programmatically from your own solution

Flexie CRM 3 Dec 30, 2021
PHP Digital Green Certificate SDK

Digital Green Certificate SDK PHP Indice Contesto Installazione Uso Licenza Dettaglio licenza Contesto Attenzione, questo repository è derivato dalle

null 9 Jan 11, 2022
Esse SDK em PHP foi desenvolvido no intuito de tornar mais prático a integração com nossa API.

Sobre Beedoo SDK Acessar documentação completa da Beedoo API. A API é organizada seguindo a arquitetura REST, boas práticas, convenções e padrões como

Beedoo Edtech 5 Dec 2, 2021
A PHP SDK for accessing the OpenAI GPT-3 API

OpenAI GPT-3 Api Client in PHP Installation You can install the package via composer: composer require orhanerday/open-ai Usage use Orhanerday\OpenAi\

Orhan erday 127 Jan 12, 2022
The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login

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

Meta Archive 3.1k Jan 10, 2022