/**
  * @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.º 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
 function token()
 {
     $qiniu = config('forone.qiniu');
     $bucket = $qiniu['bucket'];
     $auth = new Auth($qiniu['access_key'], $qiniu['secret_key']);
     return response()->json(['uptoken' => $auth->uploadToken($bucket)]);
 }
Ejemplo n.º 4
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.º 5
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.º 6
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.º 7
0
 /**
  * Constructor.
  */
 public function __construct($ak, $sk, $bucket)
 {
     $auth = new Auth($ak, $sk);
     $this->bucket = $bucket;
     $this->token = $auth->uploadToken($bucket);
     $this->uploadManager = new UploadManager();
     $this->bucketManager = new BucketManager($auth);
 }
Ejemplo n.º 8
0
 public static function getQiniuToken()
 {
     $accessKey = 'aavEmxVT7o3vsFMGKUZbJ1udnoAbucqXPmk3tdRX';
     $secretKey = 'nDQPr1L7pcurdV8_7iLIICNjSME2EmCiokHXTGTX';
     $auth = new QiniuAuth($accessKey, $secretKey);
     $bucket = 'opulent-hotel-image';
     $token = $auth->uploadToken($bucket);
     return $token;
 }
Ejemplo n.º 9
0
 public static function getUploadToken()
 {
     $accessKey = 'MV6ja7j7Z6lSJJGCs7ycWsc0-sHluayNZOcL9Yun';
     $secretKey = '-m_KorldbIhQrzGeLDOAjwP1fb8ZJZ-aBDRuEoWl';
     $auth = new Auth($accessKey, $secretKey);
     $bucket = 'chichichi';
     $token = $auth->uploadToken($bucket);
     return $token;
 }
Ejemplo n.º 10
0
 protected function get_qiniu_uptoken()
 {
     $access_key = 'lhMwghBTBfeu54AKS3NHcHRxX8IZc90Kz-MFigBg';
     $secret_key = 'DPCU0DvzVgO2DrqYGsfT1xqOumpTVvRm963x-pmR';
     $auth = new Auth($access_key, $secret_key);
     $bucket = 'erhuo-activity';
     $upToken = $auth->uploadToken($bucket);
     return $upToken;
 }
Ejemplo n.º 11
0
 /**
  * 获得七牛云token
  */
 public function getToken()
 {
     $accessKey = getenv('QINIU_ACCESSKEY');
     $secretKey = getenv('QINIU_SECRETKEY');
     $file = getenv('QINIU_FILE');
     $auth = new Auth($accessKey, $secretKey);
     $token = $auth->uploadToken($file);
     return Response::json(['code' => 0, 'message' => '申请成功!', 'token' => $token, 'qiniuhost' => getenv('QINIU_HOST')]);
 }
Ejemplo n.º 12
0
 public function actionToken()
 {
     $accessKey = 'KfjTLZlT7JQAXt0U8dOPRC7QcHu0_Z4QwWdtTAVN';
     $secretKey = '78DH5Zr7mbHtYxCJUhlfKwKUobuqJ6euyVLXA6NB';
     $auth = new Auth($accessKey, $secretKey);
     $bucket = 'peterimg';
     $upToken = ['uptoken' => $auth->uploadToken($bucket)];
     echo json_encode($upToken);
 }
Ejemplo n.º 13
0
 public function getUpToken()
 {
     $accessKey = 'ftC668Tvh8pxsfr5IEFLguzH4Huh1hRJDwDrswhu';
     $secretKey = 's6qCdCReUHy-uYjo0d_jc_ZoQjUEHw2cwu55VwXg';
     $auth = new Auth($accessKey, $secretKey);
     $bucket = 'opera';
     $upToken = $auth->uploadToken($bucket);
     return Response::json(array("uptoken" => $upToken));
 }
Ejemplo n.º 14
0
 public function init()
 {
     if (is_array($this->qiniu) && isset($this->qiniu['url']) && isset($this->qiniu['bucket']) && isset($this->qiniu['ak']) && isset($this->qiniu['sk'])) {
         $this->qiniuUrl = $this->qiniu['url'];
         $auth = new Auth($this->qiniu['ak'], $this->qiniu['sk']);
         $this->qiniuToken = $auth->uploadToken($this->qiniu['bucket']);
     } else {
         throw new InvalidConfigException('未配置七牛url/bucket/ak/sk!');
     }
 }
Ejemplo n.º 15
0
 public static function getQiniuToken()
 {
     $bucket = Yii::app()->params['partner']['qiniu']['bucket'];
     $ak = Yii::app()->params['partner']['qiniu']['ak'];
     $sk = Yii::app()->params['partner']['qiniu']['sk'];
     $domain = Yii::app()->params['partner']['qiniu']['domain'];
     $auth = new Auth($ak, $sk);
     $upToken = $auth->uploadToken($bucket);
     return array('uptoken' => $upToken, 'domain' => $domain);
 }
Ejemplo n.º 16
0
 private function qiniu()
 {
     $this->config = array_merge($this->config, Yii::$app->params['webuploader_qiniu_config']);
     $bucket = $this->config['bucket'];
     $accessKey = $this->config['accessKey'];
     $secretKey = $this->config['secretKey'];
     $auth = new Auth($accessKey, $secretKey);
     $upToken = $auth->uploadToken($bucket);
     $ret = ['uptoken' => $upToken];
     return $ret;
 }
Ejemplo n.º 17
0
 public function action_uptoken_hc51()
 {
     $qiniu_config = Kohana::config('qiniu.haoche51');
     $accessKey = $qiniu_config['access_key'];
     $secretKey = $qiniu_config['secret_key'];
     $bucket = 'haoche51post';
     $auth = new Auth($accessKey, $secretKey);
     $token = $auth->uploadToken($bucket);
     echo json_encode(array('uptoken' => $token));
     exit;
 }
Ejemplo n.º 18
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.º 19
0
 public function actionUptoken()
 {
     header('Content-type: text/json');
     //Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $accessKey = 'RDFVgI2CMVHF-79JMXbIFpy9aVz4NJSTXc_wI6u2';
     $secretKey = 'l8vY4A3juunUVePBdP298RurE4f-xznX93_eT5mN';
     $auth = new Auth($accessKey, $secretKey);
     $bucket = "yubinzaojia";
     $token = $auth->uploadToken($bucket);
     $rtn['uptoken'] = $token;
     echo json_encode($rtn);
 }
Ejemplo n.º 20
0
 public function downloadTokenOfFront()
 {
     $addr = Input::get('addr');
     if (!isset($addr)) {
         return Response::json(array('errCode' => 21, 'message' => '请传入图片名字'));
     }
     $accessKey = Config::get('qiniu.qiniu.accessKey');
     $secretKey = Config::get('qiniu.qiniu.secretKey');
     $auth = new Auth($accessKey, $secretKey);
     $baseUrl = Config::get('qiniu.domain') . $addr;
     return Response::json(array('errCode' => 21, 'message' => 'ok', 'downloadtoken' => $auth->privateDownloadUrl($baseUrl)));
 }
Ejemplo n.º 21
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.º 22
0
 function jstoken()
 {
     $accessKey = Config::getField("Qiniu", "AK");
     $secretKey = Config::getField("Qiniu", "SK");
     $auth = new Auth($accessKey, $secretKey);
     // 空间名  http://developer.qiniu.com/docs/v6/api/overview/concepts.html#bucket
     $bucket = Config::getField("Qiniu", "bucket");
     // 生成上传Token
     $token = $auth->uploadToken($bucket, $key = null, 3600, array());
     $t = array("uptoken" => $token, "domain" => Config::getField("Qiniu", "domain"));
     Response::apiJsonResult($t, 1);
 }
 public function index()
 {
     $brandLogic = D("Brand", "Logic");
     $categoryLogic = D("Category", "Logic");
     vendor("qiniusdk.autoload");
     $accessKey = 'k7HBysPt-HoUz4dwPT6SZpjyiuTdgmiWQE-7qkJ4';
     $secretKey = 'BuaBzxTxNsNUBSy1ZvFUAfUbj8GommyWbfJ0eQ2R';
     $auth = new Auth($accessKey, $secretKey);
     $bucket = 'image';
     $token = $auth->uploadToken($bucket, null, 3600, null, true);
     $this->assign('qiniuToken', $token);
     $this->assign("brandData", $brandLogic->getAllBrandInfo());
     $this->assign("categoryData", $categoryLogic->getAllCategoryInfo());
     $this->display();
 }
Ejemplo n.º 24
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.º 25
0
    public function index()
    {
        $bucket = env('BUCKET');
        $ak = env('AccessKey');
        $sk = env('SecretKey');
        $auth = new Auth($ak, $sk);
        $policy = array('callbackUrl' => env('CallBackUrl'), 'callbackBody' => '{"fname":"$(fname)", "fkey":"$(key)", "desc":"$(x:desc)", "uid":' . "Test" . '}');
        $upToken = $auth->uploadToken($bucket, null, 3600, $policy);
        echo <<<HTML
<form method="post" action="http://up.qiniu.com" enctype="multipart/form-data">
  <input name="token" type="hidden" value="{$upToken}">
  <input name="file" type="file" />
  <input type="submit" value="上传"/>
</form>  
HTML;
    }
Ejemplo n.º 26
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.º 27
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;
 }
 public function edit()
 {
     $supportingDataLogic = D("SupportingData", "Logic");
     $key = I("get.key", "");
     if ($key == "") {
         die("操作错误!");
     }
     $this->assign("data", $supportingDataLogic->getAllInformationByKey($key));
     $this->assign("dataJSON", json_encode($supportingDataLogic->getAllInformationByKey($key)));
     vendor("qiniusdk.autoload");
     $accessKey = 'k7HBysPt-HoUz4dwPT6SZpjyiuTdgmiWQE-7qkJ4';
     $secretKey = 'BuaBzxTxNsNUBSy1ZvFUAfUbj8GommyWbfJ0eQ2R';
     $auth = new Auth($accessKey, $secretKey);
     $bucket = 'image';
     $token = $auth->uploadToken($bucket, null, 3600, null, true);
     $this->assign('qiniuToken', $token);
     $this->display();
 }
Ejemplo n.º 29
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.º 30
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}");
             }
         }
     }
 }