Example #1
0
<?php

/**
 * @file test.php
 * @brief 简化版的七牛 PHP SDK 使用方法示例,为了获取 callback,本示例使用了自己的业务服务器。
 * @author JonChou <*****@*****.**>
 * @date 2013-08-29
 */
require "qiniu/Qiniu/Client.php";
// 如果你使用 composer,请不要注册自带的 autoloader。
\Qiniu\Client::registerAutoloader();
// 实例化七牛 SDK
$config = array('access_key' => 'Your access key', 'secret_key' => 'Your secret key');
$sdk = new \Qiniu\Client($config);
// 请设置为你自己的 bucket 名称
$bucket = 'sketch';
// 测试用的文件名 key
$key = 'test.png';
// 自定义 returnBody 参数,省略该参数会返回默认字段
$params = array('scope' => $bucket, 'returnBody' => '{
                                "key": $(key),
                                "name": $(fname),
                                "size": $(fsize),
                                "type": $(mimeType),
                                "hash": $(etag),
                                "w": $(imageInfo.width),
                                "h": $(imageInfo.height),
                                "description": $(x:description)
                             }', 'expires' => 3600);
if (!empty($_FILES)) {
    // 如果你只需要简单上传本地文件,这个参数设为本地文件路径即可
Example #2
0
<?php

define("ROOT", dirname(__FILE__));
include ROOT . "/Qiniu/Client.php";
\Qiniu\Client::registerAutoloader();
$bucket = "qiniu-up";
$QiniuBaseUrl = "qiniu-up.qiniudn.com";
$QiniuAccessKey = '';
$QiniuSecretKey = '';
$config = array('access_key' => $QiniuAccessKey, 'secret_key' => $QiniuSecretKey);
$sdk = new \Qiniu\Client($config);
ob_start();
$htmlFileTableHead = <<<HTML
<section class='box well'>
  <header><h2>已上传文件列表</h2></header>
  <table class="table table-striped table-bordered table-condensed">
HTML;
$htmlFileTableFooter = <<<HTML
  </table>
</section>
HTML;
switch ($_SERVER["REQUEST_METHOD"]) {
    case "POST":
        if (isset($_FILES["files"])) {
            echo $htmlFileTableHead;
            foreach ($_FILES["files"]["error"] as $key => $error) {
                if ($error == UPLOAD_ERR_OK) {
                    $tmpName = $_FILES["files"]["tmp_name"][$key];
                    $fileName = $_FILES["files"]["name"][$key];
                    $fileMD5 = md5_file($_FILES["files"]["tmp_name"][$key]);
                    $params = array('scope' => $bucket, 'expires' => 3600);