Ejemplo n.º 1
0
 public function uploadImag($fileName, $Path)
 {
     // 构建鉴权对象
     $auth = new Auth($this->accessKey, $this->secretKey);
     // 要上传的空间
     $bucket = $this->bucket;
     // 生成上传 Token
     $token = $auth->uploadToken($bucket);
     // 要上传文件的本地路径
     $filePath = $Path;
     // 上传到七牛后保存的文件名
     $key = $fileName;
     // 初始化 UploadManager 对象并进行文件的上传。
     $uploadMgr = new UploadManager();
     // 调用 UploadManager 的 putFile 方法进行文件的上传。
     list($ret, $err) = $uploadMgr->putFile($token, $key, $fileName);
     //        echo "\n====> putFile result: \n";
     if ($err !== null) {
         //            var_dump($err);
         $return['code'] = false;
         $return['content'] = $err;
     } else {
         $return['code'] = true;
         $return['content'] = $ret;
     }
     return $return;
 }
Ejemplo n.º 2
0
 public function uploadImg()
 {
     $file = Input::file('file');
     if (!$file->isValid()) {
         return back();
     } else {
         $allowed_extensions = ["png", "jpg", "gif"];
         if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
             return ['error' => '上传失败'];
         }
         // 需要填写你的 Access Key 和 Secret Key
         $accessKey = 'wljtjmpVhsu7OvBBLsU-w-LYtjce9iyMEstqcBXm';
         $secretKey = 'EmjQ7c2YlBs42vWPJUiCBzvmCKRRIntV3MBgE_1A';
         // 构建鉴权对象
         $auth = new Auth($accessKey, $secretKey);
         // 要上传的空间
         $bucket = 'pictures';
         // 生成上传 Token
         $token = $auth->uploadToken($bucket);
         // 要上传文件的本地路径
         $filePath = $file->getRealPath();
         // 上传到七牛后保存的文件名
         $key = time() . rand(100, 999) . '.jpg';
         // 初始化 UploadManager 对象并进行文件的上传
         $uploadMgr = new UploadManager();
         // 调用 UploadManager 的 putFile 方法进行文件的上传
         list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
         if ($err !== null) {
             return ['error' => '上传失败'];
         } else {
             $path = 'http://7xs3aa.com1.z0.glb.clouddn.com/' . $ret['key'];
             return Response::json(['success' => true, 'pic' => $path]);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $file = $request->file('video');
     // 需要填写你的 Access Key 和 Secret Key
     $accessKey = 'TJSVBy7AbnLq1qWcK5-yEQQ-M_llQErT-I2mUO02';
     $secretKey = '8m_yl8ZQ816NhQWEMRrF6JI3ajS_mwoJqToXr12w';
     // 构建鉴权对象
     $auth = new Auth($accessKey, $secretKey);
     // 要上传的空间
     $bucket = 'myfirstspace';
     // 生成上传 Token
     $token = $auth->uploadToken($bucket);
     // 要上传文件的本地路径
     $filePath = $file;
     // 上传到七牛后保存的文件名
     $key = $request['name'];
     // 初始化 UploadManager 对象并进行文件的上传。
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
     echo "\n====> putFile result: \n";
     if ($err !== null) {
         var_dump($err);
     } else {
         var_dump($ret);
     }
 }
Ejemplo n.º 4
0
 /**
  * 文件上传
  * @throws \Exception
  */
 public function upload()
 {
     // 要上传的空间
     $bucket = "genffy";
     // 生成上传 Token
     $token = self::auth()->uploadToken($bucket);
     // 要上传文件的本地路径
     $floder = Storage::disk("local");
     $filePath = $floder->getDriver()->getAdapter()->getPathPrefix() . "头像.png";
     // 上传到七牛后保存的文件名
     $key = md5($filePath) . ".png";
     // 初始化 UploadManager 对象并进行文件的上传。
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
     echo "\n====> putFile result: \n";
     if ($err !== null) {
         var_dump($err);
     } else {
         // 返回下载链接
         $time = time() + 7 * 24 * 60 * 60;
         $url = self::QI_NIU_DOMAIN . $ret["key"] . "?e={$time}";
         $sign = hash_hmac('sha1', $url, self::getKey("secret"), true);
         $token = self::getKey("access") . ":" . self::urlsafe_base64_encode($sign);
         $realUrl = $url . "&token={$token}";
         echo "<a href='{$realUrl}' target='_blank'>头像</a>";
     }
 }
Ejemplo n.º 5
0
 /**
  * 上传图片
  * @param  [type] $imgName [文件名]
  * @param  [type] $content [二进制流]
  * @return [type]          [description]
  */
 public function uploadImage($imgName, $content)
 {
     $token = $this->auth->uploadToken($this->bucket);
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->put($token, $imgName, $content);
     return $this->response($err, $imgName);
 }
 /**
  * @param   class   doUpload    文件上传封装类
  * @const   ACCESS  SECRET      七牛云的秘钥
  * @param   array   $file       前台name的上传文件名
  * @return  string  $key        文件路径
  * @author   GIO    645074190@qq.com
  */
 public function doUpload($file = array())
 {
     vendor('php-sdk-master.autoload');
     $auth = new Auth(self::ACCESS, self::SECRET);
     //实例化一个Auth类
     $bucket = 'xmmusic';
     //要上传的空间名
     $token = $auth->uploadToken($bucket);
     //生成上传的Token
     $filePath = $file['tmp_name'];
     //上传的本地文件路径
     $str = $file['name'];
     $pathInfo = pathinfo($str);
     $suffix = $pathInfo['dirname'] . $pathInfo['extension'];
     //生成上传文件的后缀名
     if (empty($suffix)) {
         $this->error('请上传扫描文件', 'index');
     } else {
         $key = date('Ymd', time()) . mt_rand(1000, 9000) . $suffix;
         /*上传到七牛云后保存的随机文件名*/
         $uploadMgr = new UploadManager();
         /*初始化 UploadManager 对象并进行文件的上传*/
         list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
         return $key;
     }
 }
Ejemplo n.º 7
0
 public function PutImgFile($filename, $filePath)
 {
     // 生成上传Token
     $token = $this->auth->uploadToken($this->bucket);
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->putFile($token, $filename, $filePath);
     return $err !== null ? false : DEFAULT_URL . $ret['key'];
 }
Ejemplo n.º 8
0
 public function PutImgFile($filename, $filePath, $category)
 {
     // 生成上传Token
     $token = $this->auth->uploadToken($this->bucket);
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->putFile($token, $filename, $filePath);
     return $err !== null ? '' : QINIU_DIR_THUMB . $ret['key'] . $category;
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function write($path, $contents, Config $config)
 {
     list($ret, $error) = $this->uploadManager->put($this->token, $path, $contents);
     if ($error) {
         return false;
     }
     return $ret;
 }
Ejemplo n.º 10
0
 /**
  * 生成二维码并上传到七牛
  *
  * @param $file_name    文件名
  * @param $content      二维码内容
  * @param $error        二维码容错级别
  * @param $size         二维码大小
  *
  * @return array    包含已上传文件的信息,类似:
  *                                              [
  *                                                  "hash" => "<Hash string>",
  *                                                  "key" => "<Key string>"
  *                                              ]
  */
 public static function create_and_upload($file_name, $content, $error = 'L', $size = 6)
 {
     $qiniu_config = Config::get('qiniu');
     $qiniu_uploader = new UploadManager();
     $auth = new Auth($qiniu_config['accessKey'], $qiniu_config['secretKey']);
     $file_full_path = self::create_qrcode($file_name, $content, $error, $size);
     return $qiniu_uploader->putFile($auth->uploadToken($qiniu_config['buckets'][0]), $file_name, $file_full_path);
 }
Ejemplo n.º 11
0
 public function testFile2()
 {
     $key = 'formPutFile';
     $token = $this->auth->uploadToken($this->bucketName, $key);
     $upManager = new UploadManager();
     list($ret, $error) = $upManager->putFile($token, $key, __FILE__, null, 'text/plain', true);
     $this->assertNull($error);
     $this->assertNotNull($ret['hash']);
 }
Ejemplo n.º 12
0
 /**
  * 上传数据流到七牛
  * @param $fileName     存储文件名
  * @param $content      内容
  * @return bool
  */
 public function uploadStream($fileName, $content)
 {
     $client = new UploadManager();
     list($ret, $err) = $client->put($this->token, $fileName, $content);
     if ($err != null) {
         return false;
     }
     return $ret;
 }
Ejemplo n.º 13
0
 function put($key, $filePath)
 {
     $uploadMgr = new UploadManager();
     list($res, $err) = $uploadMgr->putFile($this->token, $key, $filePath);
     if ($err !== null) {
         throw $err;
     } else {
         return true;
     }
 }
Ejemplo n.º 14
0
 /**
  * 上传文件
  * @param string $filePath 本地文件路径
  * @param string $key 保存到七牛的文件名称
  * @param null $policy
  * @throws \Exception
  * @return bool
  */
 public function upload($filePath, $key, $policy = null)
 {
     $token = $this->generateToken($policy);
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
     if ($err !== null) {
         $this->addError(json_encode($err));
         return false;
     }
     return true;
 }
Ejemplo n.º 15
0
 public function test4ML()
 {
     $key = 'resumePutFile4ML';
     $upManager = new UploadManager();
     $token = $this->auth->uploadToken($this->bucketName, $key);
     $tempFile = qiniuTempFile(4 * 1024 * 1024 + 10);
     list($ret, $error) = $upManager->putFile($token, $key, $tempFile);
     $this->assertNull($error);
     $this->assertNotNull($ret['hash']);
     unlink($tempFile);
 }
Ejemplo n.º 16
0
 public function saveImage($tmpFile)
 {
     $upManager = new UploadManager();
     $auth = new Auth($this->config['accessToken'], $this->config['secretToken']);
     $token = $auth->uploadToken($this->config['bucketName']);
     $uploadName = date('Y/m/d/') . Str::lower(Str::quickRandom()) . '.jpg';
     list($ret, $error) = $upManager->put($token, $uploadName, file_get_contents($tmpFile));
     if (!$ret) {
         throw new Exception($error->message());
     }
     return rtrim($this->config['baseUrl'], '/') . '/' . $uploadName;
 }
Ejemplo n.º 17
0
 public function upload($file)
 {
     $auth = new QA(env('ACCESS_KEY'), env('SECRET_KEY'));
     $bucket = env('QINIU_BUCKET');
     $token = $auth->uploadToken($bucket);
     $key = md5($file);
     $uploadMgr = new UploadManager();
     if ($uploadMgr->putFile($token, $key, $file)) {
         return true;
     }
     return false;
 }
Ejemplo n.º 18
0
 public function test4ML2()
 {
     $key = 'resumePutFile4ML';
     $zone = new Zone('http://up.fake.com', 'http://up.qiniu.com');
     $cfg = new Config($zone);
     $upManager = new UploadManager($cfg);
     $token = $this->auth->uploadToken($this->bucketName, $key);
     $tempFile = qiniuTempFile(4 * 1024 * 1024 + 10);
     list($ret, $error) = $upManager->putFile($token, $key, $tempFile);
     $this->assertNull($error);
     $this->assertNotNull($ret['hash']);
     unlink($tempFile);
 }
Ejemplo n.º 19
0
 public function save($fileObject)
 {
     $token = $this->auth->uploadToken($this->bucket);
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->putFile($token, null, $fileObject->getPathname());
     if (!$err) {
         $data['ident'] = $ret['key'];
         $data['url'] = '/' . $ret['key'];
         return $data;
     } else {
         throw new Exception($err);
     }
 }
Ejemplo n.º 20
0
 public function upload($url)
 {
     $data = array();
     $token = $this->auth->uploadToken($this->bucket);
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->put($token, null, file_get_contents($url));
     if ($err !== null) {
         return $data;
     } else {
         $data = array('url' => $this->domain . $ret['key'], 'key' => $ret['key']);
     }
     return $data;
 }
Ejemplo n.º 21
0
 static function upload_content($content, $remote_path)
 {
     if (substr($remote_path, 0, 1) == "/") {
         $remote_path = substr($remote_path, 1);
     }
     $upToken = self::get_uptoken();
     //echo $upToken;exit;
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->put($upToken, $remote_path, $content);
     if ($err !== null) {
         throw new Exception($err->getResponse()->error, $err->getResponse()->statusCode);
     }
     return $ret;
 }
Ejemplo n.º 22
0
 /**
  *   上传头像
  *   图片上传成功后做标记,渲染裁剪功能,裁剪后坐标传送给Headcut,Headcut进行裁剪,保存图片,标记。
  */
 public function actionIndex()
 {
     //如果用户上传了头像图片
     if (!empty($_FILES['headpic'])) {
         //进行本地上传
         $user = User::find()->where(['id' => $_GET['id']])->one();
         $image = UploadedFile::getInstanceByName('headpic');
         $imageName = $user->id . '_' . time() . '.' . $image->getExtension();
         if ($image->saveAs('uploads/head/' . $imageName)) {
             //上传到本地成功,进行图片处理
             //组装文件名
             $imagePath = Yii::getAlias('@root') . '\\frontend\\web\\uploads\\head\\' . $imageName;
             // 处理成功后 传入七牛
             //配置七牛的参数
             $accessKey = Yii::getAlias('@accessKey');
             $secretKey = Yii::getAlias('@secretKey');
             $auth = new Auth($accessKey, $secretKey);
             $bucket = 'colfans-uploads-public';
             $token = $auth->uploadToken($bucket);
             $uploadMgr = new UploadManager();
             list($ret, $err) = $uploadMgr->putFile($token, $imageName, $imagePath);
             if ($err !== null) {
                 //上传不成功
                 echo 'no';
             } else {
                 //上传成功
                 //删除本地文件
                 unlink($imagePath);
                 //更新数据库头像
                 $oldHeadFile = $user->head;
                 $user->head = $imageName;
                 if ($user->save()) {
                     //删除七牛原有的头像图片
                     $bucketMgr = new BucketManager($auth);
                     $err = $bucketMgr->delete($bucket, $oldHeadFile);
                     if ($err !== null) {
                         echo 'no';
                     } else {
                         echo 'yes';
                     }
                 }
             }
         } else {
         }
     } else {
         return $this->render('headupload', ['title' => '个人资料', 'category' => '账号管理', 'subcate' => '个人资料']);
     }
 }
Ejemplo n.º 23
0
 public static function uploadPic($filePath)
 {
     // 设置信息
     $APP_ACCESS_KEY = 'VDo2clWr4g7DJ2d1S8h_8W17d2RzmMdrywI-TiBm';
     $APP_SECRET_KEY = 'H7Axjej_QhlpgbAry4rVNyoBOnNj9etSfWYcHXi7';
     $bucket = 'che123';
     $auth = new Auth($APP_ACCESS_KEY, $APP_SECRET_KEY);
     $token = $auth->uploadToken($bucket);
     $uploadManager = new UploadManager();
     $name = time() . '_' . rand() . '.png';
     list($ret, $err) = $uploadManager->putFile($token, 'app_ico/' . $name, $filePath);
     if ($err != null) {
         return ["success" => false, "msg" => "上传失败。错误消息:" . $err->message()];
     } else {
         return ["success" => true, "msg" => "上传成功。Key:" . $ret["key"], 'name' => $name];
     }
 }
Ejemplo n.º 24
0
 public function uploadQiniu($key, $content)
 {
     $upManager = new UploadManager();
     $auth = new Auth(config('UEditorUpload.core.qiniu.accessKey'), config('UEditorUpload.core.qiniu.secretKey'));
     $token = $auth->uploadToken(config('UEditorUpload.core.qiniu.bucket'));
     list($ret, $error) = $upManager->put($token, $key, $content);
     if ($error) {
         $this->stateInfo = $error->message();
     } else {
         //change $this->fullName ,return the url
         $url = rtrim(strtolower(config('UEditorUpload.core.qiniu.url')), '/');
         $fullName = ltrim($this->fullName, '/');
         $this->fullName = $url . '/' . $fullName;
         $this->stateInfo = $this->stateMap[0];
     }
     return true;
 }
Ejemplo n.º 25
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Image();
     $catlist = Category::getDropList(1);
     if (isset($_POST['Image'])) {
         $model->attributes = $_POST['Image'];
         $model->create_uid = Yii::app()->user->id;
         $model->create_at = time();
         $accessKey = 'alO3SWK6jx4XvPSeUCbhRRb8arS8sivFSQ_zMo1K';
         $secretKey = 'qZlz5D8-Wlj0nUnsRt-qTNit56dVcWb2jK_eVqcK';
         $auth = new Auth($accessKey, $secretKey);
         $bucket = 's-nice';
         // 生成上传 Token
         $token = $auth->uploadToken($bucket);
         $img = CUploadedFile::getInstance($model, 'img');
         if ($img) {
             $savename = time() . mt_rand(1, 99999) . '.' . $img->extensionName;
             $model->img = $savename;
             if ($model->validate()) {
                 $img->saveAs(Yii::app()->params['uploadPath'] . $savename);
             }
         }
         $filePath = Yii::app()->params['uploadPath'] . $savename;
         // 上传到七牛后保存的文件名
         $key = $savename;
         // 初始化 UploadManager 对象并进行文件的上传。
         $uploadMgr = new UploadManager();
         // 调用 UploadManager 的 putFile 方法进行文件的上传。
         list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
         $token = $auth->uploadToken($bucket);
         // 构建 UploadManager 对象
         $uploadMgr = new UploadManager();
         if (file_exists(Yii::app()->params['uploadPath'] . $savename)) {
             unlink(Yii::app()->params['uploadPath'] . $savename);
         }
         if ($model->save()) {
             Yii::app()->user->setFlash('success', '信息提交成功!');
         } else {
             Yii::app()->user->setFlash('success', '信息提交失败!');
         }
     }
     $this->render('create', array('model' => $model, 'catlist' => $catlist));
 }
Ejemplo n.º 26
0
 public function main($argc, $argv)
 {
     // 需要填写你的 Access Key 和 Secret Key
     $accessKey = 'degc0lsSBdDrin_ccL4q6yMdLUPvMkSIQONrFjWw';
     $secretKey = 'ePoKmcSWuBOBFEehJHKAKaErCkhO42jmUVNLDCrl';
     // 要上传的空间
     $bucket = 'fimg';
     //$bucket = 'static';
     // 从数据库获取要生成的player ids
     $playerIds = $this->getPlayerIds();
     if (!empty($playerIds)) {
         // 构建鉴权对象
         $auth = new Auth($accessKey, $secretKey);
         // 生成上传 Token
         $token = $auth->uploadToken($bucket);
         // 初始化 UploadManager 对象
         $uploadMgr = new UploadManager();
         foreach ($playerIds as $id) {
             $qrinfo = self::SITE_DOMAIN . 'player/' . $id . '?f=qr';
             $path = '/a/player/qrcode/' . $id . '.png';
             $locfile = SIMPHP_ROOT . $path;
             //生成二维码
             QRcode::png($qrinfo, $locfile, QR_ECLEVEL_L, 7, 3);
             //更新qrcode字段
             $this->updateFields($id, ['qrcode' => $path]);
             // 上传到七牛后保存的文件名
             $key = $this->qiniu_filekey(basename($path));
             // 上传文件
             list($ret, $err) = $uploadMgr->putFile($token, $key, $locfile);
             if ($err !== null) {
                 //失败
                 $this->log("[FAIL]player_id={$id},locpath={$locfile},err=" . $err->message());
             } else {
                 //成功
                 $path_qn = $this->qiniu_filepath($ret['key']);
                 //更新qrcode字段
                 $this->updateFields($id, ['qrcode_cdn' => $path_qn]);
                 $this->log("[SUCC]player_id={$id},locpath={$locfile} >> {$path_qn}");
             }
         }
     }
 }
Ejemplo n.º 27
0
 protected function upload_to_qiniu()
 {
     //        if (($_FILES["file"]["type"] == "image/gif")
     //            || ($_FILES["file"]["type"] == "image/jpeg")
     //            || ($_FILES["file"]["type"] == "image/png")
     //            || ($_FILES["file"]["type"] == "image/pjpeg"))
     //        {
     if ($_FILES["media"]["error"] > 0) {
         echo "Error: " . $_FILES["media"]["error"] . "<br />";
     } else {
         //                echo "Upload: " . $_FILES["media"]["name"] . "<br />";
         //                echo "Type: " . $_FILES["media"]["type"] . "<br />";
         //                echo "Size: " . ($_FILES["media"]["size"] / 1024) . " Kb<br />";
         //                echo "Stored in: " . $_FILES["media"]["tmp_name"];
         $file_path1 = $_FILES['media']['tmp_name'];
         $file_name1 = $_FILES['media']['name'];
     }
     //        }
     $uploadMgr = new UploadManager();
     $token = $this->get_qiniu_uptoken();
     list($ret1, $err1) = $uploadMgr->putFile($token, $file_name1, $file_path1);
     return $ret1['key'];
 }
Ejemplo n.º 28
0
 public function test()
 {
     $accessKey = 'I95WDMPsR900aTLfmFnx0Z_TBP--sdS6qofwnwRo';
     $secretKey = 'VsrVogbHKRQDZitBGNC-FO-gYeLkXAzGeVRRhqKJ';
     $auth = new Auth($accessKey, $secretKey);
     // 要上传的空间
     $bucket = 'sylsong';
     // 生成上传 Token
     $token = $auth->uploadToken($bucket);
     // 要上传文件的本地路径
     $filePath = dirname(APP_PATH) . '/123.jpg';
     // 上传到七牛后保存的文件名
     $key = 'hehe.png';
     // 初始化 UploadManager 对象并进行文件的上传。
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
     echo "\n====> putFile result: \n";
     if ($err !== null) {
         $rr = "error";
     } else {
         $rr = "success";
     }
     echo $rr;
 }
Ejemplo n.º 29
0
<?php

require_once __DIR__ . '/../autoload.php';
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
$auth = new Auth($accessKey, $secretKey);
$bucket = 'Bucket_Name';
$token = $auth->uploadToken($bucket);
$uploadMgr = new UploadManager();
//----------------------------------------upload demo1 ----------------------------------------
// 上传字符串到七牛
list($ret, $err) = $uploadMgr->put($token, null, 'content string');
echo "\n====> put result: \n";
if ($err !== null) {
    var_dump($err);
} else {
    var_dump($ret);
}
//----------------------------------------upload demo2 ----------------------------------------
// 上传文件到七牛
$filePath = './php-logo.png';
$key = 'php-logo.png';
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
echo "\n====> putFile result: \n";
if ($err !== null) {
    var_dump($err);
} else {
    var_dump($ret);
}
Ejemplo n.º 30
0
<?php

require_once __DIR__ . '/../autoload.php';
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
$auth = new Auth($accessKey, $secretKey);
$bucket = 'Bucket_Name';
// 上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器.
// 可参考文档: http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html
$policy = array('callbackUrl' => 'http://your.domain.com/callback.php', 'callbackBody' => 'filename=$(fname)&filesize=$(fsize)');
$uptoken = $auth->uploadToken($bucket, null, 3600, $policy);
//上传文件的本地路径
$filePath = './php-logo.png';
$uploadMgr = new UploadManager();
list($ret, $err) = $uploadMgr->putFile($uptoken, null, $filePath);
echo "\n====> putFile result: \n";
if ($err !== null) {
    var_dump($err);
} else {
    var_dump($ret);
}