Home > Backend Development > PHP Tutorial > 七牛云存储 - 七牛:php 生成带多个策略的 token 的问题

七牛云存储 - 七牛:php 生成带多个策略的 token 的问题

WBOY
Release: 2016-06-06 20:35:36
Original
1652 people have browsed it

我之前一直这样生成七牛的token :

<code>    $bucket = "";     //你的七牛云存储的空间名称
    $accessKey = '';  //公钥
    $secretKey = '';  //密钥

    Qiniu_SetKeys($accessKey, $secretKey);
    $putPolicy = new Qiniu_RS_PutPolicy($bucket);
    //生成token
    $token = $putPolicy->Token(null);
</code>
Copy after login
Copy after login

现在我想放多一些策略,比如图片大小,图片重命名,允许上传的文件类型等,于是,我构造了这样的方法:

<code>$policy= array(
    "scope"=>"",          //存储的空间名称
    "saveKey"=>"",        //重命名
    "fsizeLimit"=>"",     //文件大小
    "mimeLimit"=>""       // 文件类型"
);
$accessKey = ''; //公钥
$secretKey = ''; //密钥

Qiniu_SetKeys($accessKey, $secretKey);
$putPolicy = new Qiniu_RS_PutPolicy($policy);//把策略放这里
//生成token
$token = $putPolicy->Token(null);
</code>
Copy after login
Copy after login

现在,我就遇到麻烦了,这样子是生成不了token的,而第一个方法中,我是成功生成了token的,我本来想下载php jdk来处理这个问题,但似乎我没有看懂,请问有谁能帮我一下?

回复内容:

我之前一直这样生成七牛的token :

<code>    $bucket = "";     //你的七牛云存储的空间名称
    $accessKey = '';  //公钥
    $secretKey = '';  //密钥

    Qiniu_SetKeys($accessKey, $secretKey);
    $putPolicy = new Qiniu_RS_PutPolicy($bucket);
    //生成token
    $token = $putPolicy->Token(null);
</code>
Copy after login
Copy after login

现在我想放多一些策略,比如图片大小,图片重命名,允许上传的文件类型等,于是,我构造了这样的方法:

<code>$policy= array(
    "scope"=>"",          //存储的空间名称
    "saveKey"=>"",        //重命名
    "fsizeLimit"=>"",     //文件大小
    "mimeLimit"=>""       // 文件类型"
);
$accessKey = ''; //公钥
$secretKey = ''; //密钥

Qiniu_SetKeys($accessKey, $secretKey);
$putPolicy = new Qiniu_RS_PutPolicy($policy);//把策略放这里
//生成token
$token = $putPolicy->Token(null);
</code>
Copy after login
Copy after login

现在,我就遇到麻烦了,这样子是生成不了token的,而第一个方法中,我是成功生成了token的,我本来想下载php jdk来处理这个问题,但似乎我没有看懂,请问有谁能帮我一下?

看你的代码,用的应该是6.x版本的sdk,而设置上传策略的方法用的是7.x版本的方法,所以肯定会是有问题的。

6.x版本php sdk的文档可以参考 http://developer.qiniu.com/docs/v6/sdk/legacy-php-sdk.html

另外你这里修改成下面这样应该是可以的:

<code>$bucket = "";
$putPolicy = new Qiniu_RS_PutPolicy("$bucket");
$putPolicy->SaveKey = "";
$putPolicy->FsizeLimit = "";
$putPolicy->MimeLimit= "";

$accessKey = ''; //公钥
$secretKey = ''; //密钥

Qiniu_SetKeys($accessKey, $secretKey);
$upToken = $putPolicy->Token(null);
echo $upToken;
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template