API文档写的太烂,给大家个简单案例。
先下载phpsdk,传到sae空间上,新建个token.php,用来生成上传凭证。找到自己的accessKey ,secretKey,bucket(就是建立的空间名)
<?php
require_once('qiniu/rs.php');
$accessKey = 'XXX';
$secretKey = 'XXX';
Qiniu_setKeys($accessKey, $secretKey);
$bucket = 'yiweitest';
$putPolicy = new Qiniu_RS_PutPolicy($bucket);
$upToken = $putPolicy->Token(null);
echo $upToken;
?>
获取到这个token的路径,如http://xxx.sinaapp.com/token.php
建立客户端测试程序upload.php,也传到sae上,一些非必要的参数省去,主要就是获取上传凭证。
<?php
$url='http://xxx.sinaapp.com/token.php';
$token=file_get_contents($url);
?>
<form method="post" action="http://upload.qiniu.com/" enctype="multipart/form-data">
<input name="token" type="hidden" value="<?php echo $token;?>">
<input name="file" type="file" />
<input name="upload" type="submit" value="上传" />
</form>