public static function initSDK($accesskey, $sercetkey)
 {
     // 调用 SDK 设置密钥
     require_once 'sdk/io.php';
     require_once 'sdk/rs.php';
     Qiniu_SetKeys($accesskey, $sercetkey);
 }
Exemple #2
0
function initKeys()
{
    global $accessKey, $secretKey;
    if (!empty($accessKey) && !empty($secretKey)) {
        Qiniu_SetKeys($accessKey, $secretKey);
    }
}
Exemple #3
0
 private function deleteResByTopicIDArray($badTopicList)
 {
     if (empty($badTopicList)) {
         return true;
     }
     require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'third_party' . DIRECTORY_SEPARATOR . 'qiniu' . DIRECTORY_SEPARATOR . 'rs.php';
     if (!empty($badTopicList)) {
         foreach ($badTopicList as $key => $topic) {
             $resUrl = $topic['resUrl'];
             if (!empty($resUrl)) {
                 $qn = getQNFromUrl($resUrl);
                 Qiniu_SetKeys(JY_QN_accessKey, JY_QN_secretKey);
                 $client = new Qiniu_MacHttpClient(null);
                 $err = Qiniu_RS_Move($client, $qn['bucket'], $qn['key'], JY_QN_bucket_recycle, $qn['key']);
                 if ($err !== null && $err->Code != 612) {
                     $this->topic->insertBadTopic($topic['id'], $resUrl, $err->Code);
                     return false;
                 } else {
                     return true;
                 }
             }
         }
     }
     return true;
 }
Exemple #4
0
 public function save($url, $config)
 {
     set_time_limit(0);
     if (empty($url)) {
         return '';
     }
     $ext = strrchr($url, ".");
     if ($ext != ".jpeg" && $ext != ".gif" && $ext != ".jpg" && $ext != ".png") {
         return "";
     }
     $filename = random(30) . $ext;
     if (!$this->check_remote_file_exists($url)) {
         return "";
     }
     $contents = @file_get_contents($url);
     $storename = $filename;
     $bu = $config['bucket'] . ":" . $storename;
     $accessKey = $config['access_key'];
     $secretKey = $config['secret_key'];
     Qiniu_SetKeys($accessKey, $secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($bu);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     list($ret, $err) = Qiniu_Put($upToken, $storename, $contents, $putExtra);
     if (!empty($err)) {
         return "";
     }
     return 'http://' . trim($config['url']) . "/" . $ret['key'];
 }
Exemple #5
0
 public function upload_qiniu($file = "", $name = "")
 {
     $path = $_SERVER['DOCUMENT_ROOT'];
     require_once $path . "/app/libraries/qiniu/rs.php";
     require_once $path . "/app/libraries/qiniu/io.php";
     $bucket = "meilimei";
     $local_file = "upload/" . $name;
     $key = $local_file;
     $accessKey = 'tjtiZoMyJa9ggnNisrdocCCGvTlNLFvYxGMMQ6LF';
     $secretKey = '6zQXHont_jN-QFznn96H4oKA7IUqjibPeC-Yto62';
     Qiniu_SetKeys($accessKey, $secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($bucket);
     $upToken = $putPolicy->Token(null);
     if (move_uploaded_file($file, $local_file)) {
         $upload_file = $path . "/upload/" . $name;
         $putExtra = new Qiniu_PutExtra();
         $putExtra->Crc32 = 1;
         list($ret, $err) = Qiniu_PutFile($upToken, $key, $upload_file, $putExtra);
         if ($err !== null) {
             return false;
         } else {
             //var_dump($ret);
             return $ret;
         }
     } else {
         return false;
         // 			echo "move_uploaded错误!";
         // 			die;
     }
     return false;
 }
Exemple #6
0
 public function __construct($accessKey, $secretKey, $bucket)
 {
     $this->bucket = $bucket;
     require_once "qiniu/rs.php";
     Qiniu_SetKeys($accessKey, $secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($bucket);
     $this->putPolicy = $putPolicy;
 }
Exemple #7
0
 public function upload($key, $source)
 {
     Qiniu_SetKeys($this->accessKey, $this->secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     return Qiniu_PutFile($upToken, $key, $source, $putExtra);
 }
Exemple #8
0
 public function __construct(ContainerInterface $container, $accessKey, $secretKey, $bucket, $domain)
 {
     $this->container = $container;
     $this->accessKey = $accessKey;
     $this->secretKey = $secretKey;
     $this->bucket = $bucket;
     $this->domain = $domain;
     Qiniu_SetKeys($this->accessKey, $this->secretKey);
     $this->client = new \Qiniu_MacHttpClient(null);
 }
Exemple #9
0
 /**
  * Get qiniu token
  * @param null $key
  * @return string qiniu token
  */
 public function getToken($key = null)
 {
     Qiniu_SetKeys($this->accessKey, $this->secretKey);
     $scope = $this->bucket;
     if (!empty($key)) {
         // allowed to overwrite the file
         $scope .= ':' . $key;
     }
     $putPolicy = new \Qiniu_RS_PutPolicy($scope);
     $upToken = $putPolicy->Token(null);
     return $upToken;
 }
Exemple #10
0
 /**
  * 设置路径
  * @param $key
  * @param null $returnUrl
  * @param null $returnBody
  * @return string
  */
 public function getSign($preKey = '', $returnUrl = null, $returnBody = null)
 {
     Qiniu_SetKeys(Yii::app()->params['QINIU_ACCESS_KEY'], Yii::app()->params['QINIU_SECRET_KEY']);
     $putPolicy = new Qiniu_RS_PutPolicy(Yii::app()->params['QINIU_BUCKET']);
     $putPolicy->Expires = 60 * 30;
     $putPolicy->SaveKey = $preKey . '$(etag)';
     $putPolicy->MimeLimit = 'image/*';
     if ($returnUrl !== null) {
         $putPolicy->CallbackUrl = $returnUrl;
     }
     if ($returnBody !== null) {
         $putPolicy->CallbackBody = urldecode(http_build_query($returnBody));
     }
     $upToken = $putPolicy->Token(null);
     return $upToken;
 }
Exemple #11
0
 function qiniu()
 {
     echo 'qiniu';
     $bucket = "xappqiniu";
     $key = "apartment_1.jpg";
     $accessKey = 'f9zK0PZeWtFNGY5lxrXeOM6MphG2xxNYBuXv6fGn';
     $secretKey = 'PFSvanHSINAYXoW_-PBTUUNpkA7IU-w7q3pQ1JNj';
     Qiniu_SetKeys($accessKey, $secretKey);
     $client = new Qiniu_MacHttpClient(null);
     list($ret, $err) = Qiniu_RS_Stat($client, $bucket, $key);
     echo "Qiniu_RS_Stat result: \n";
     if ($err !== null) {
         var_dump($err);
     } else {
         var_dump($ret);
     }
 }
Exemple #12
0
 function __construct($params)
 {
     /** 实例化*/
     $this->ci =& get_instance();
     require_once "qiniu/io.php";
     require_once "qiniu/rs.php";
     //
     $this->accessKey = $params['accesskey'];
     $this->secretKey = $params['secretkey'];
     $this->bucket = $params['bucket'];
     $this->file_domain = $params['file_domain'];
     $key = 'test.png';
     Qiniu_SetKeys($this->accessKey, $this->secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
     $this->upToken = $putPolicy->Token(null);
     $this->putExtra = new Qiniu_PutExtra();
     $this->putExtra->Crc32 = 1;
 }
Exemple #13
0
 public function doMobileUpload()
 {
     require_once "qiniu.config.php";
     global $_GPC;
     $serverId = $_GPC['serverId'];
     //获取音频链接
     $fileName = substr($serverId, -10) . '.amr';
     $url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $this->jssdk->getAccessToken() . '&media_id=' . $serverId;
     $body = $this->jssdk->HttpGet($url);
     // 上传至七牛
     Qiniu_SetKeys($qiniu['accessKey'], $qiniu['secretKey']);
     $putPolicy = new Qiniu_RS_PutPolicy($qiniu['bucket']);
     $upToken = $putPolicy->Token(null);
     list($ret, $err) = Qiniu_Put($upToken, $fileName, $body, null);
     if ($err !== null) {
         var_dump($err);
     } else {
         // var_dump($ret);
         echo 'http://' . $qiniu['domainName'] . '/' . $fileName;
     }
 }
Exemple #14
0
 public function getImageView($mode = 0, $width = '', $height = '', $format = '', $interlace = '')
 {
     require_once LIBPATH . 'Qiniu/rs.php';
     require_once LIBPATH . 'Qiniu/fop.php';
     $domain = $this->bucket . '.qiniudn.com';
     Qiniu_SetKeys($this->accessKey, $this->secretKey);
     //生成baseUrl
     $baseUrl = Qiniu_RS_MakeBaseUrl($domain, $filename);
     //生成fopUrl
     $imgView = new Qiniu_ImageView();
     $imgView->Mode = $mode;
     $imgView->Width = $width;
     $imgView->Height = $height;
     $imgView->Format = $format;
     $imgView->Interlace = $interlace;
     $imgViewUrl = $imgView->MakeRequest();
     //对fopUrl 进行签名,生成privateUrl。 公有bucket 此步可以省去。
     // $getPolicy = new Qiniu_RS_GetPolicy();
     // return $getPolicy->MakeRequest($imgViewUrl, null);
     return $imgViewUrl;
 }
Exemple #15
0
 /**
  * 文件上传
  * @param string $filePath 待上传文件的绝对路径
  * @return string 上传成功后的URL,失败时返回空
  */
 public function uploadFile($filePath)
 {
     $fileUrl = '';
     if (!file_exists($filePath)) {
         return $fileUrl;
     }
     $config = $this->config;
     $fileName = date('YmdHis_', $_SERVER['REQUEST_TIME']) . md5(PhalApi_Tool::createRandStr(8) . microtime(true));
     Qiniu_SetKeys($config['accessKey'], $config['secretKey']);
     $putPolicy = new Qiniu_RS_PutPolicy($config['space_bucket']);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $fileName, $filePath, $putExtra);
     if ($err !== null) {
         DI()->logger->debug('failed to upload file to qiniu', array('Err' => $err->Err, 'Reqid' => $err->Reqid, 'Details' => $err->Details, 'Code' => $err->Code));
     } else {
         $fileUrl = $config['space_host'] . '/' . $fileName;
         DI()->logger->debug('succeed to upload file to qiniu', $ret);
     }
     return $fileUrl;
 }
Exemple #16
0
 /**
  * 设置路径
  * @param string $preKey
  * @param string $suffix
  * @param null $returnUrl
  * @param null $returnBody
  * @param null $persistentOps
  * @param null $persistentUrl
  * @param null $pipeline
  * @return string
  */
 public function getSign($preKey = '', $suffix = '', $returnUrl = null, $returnBody = null, $persistentOps = null, $persistentUrl = null, $pipeline = null)
 {
     Qiniu_SetKeys(Yii::app()->params['QINIU']['ACCESS_KEY'], Yii::app()->params['QINIU']['SECRET_KEY']);
     $putPolicy = new Qiniu_RS_PutPolicy(Yii::app()->params['QINIU']['BUCKET']);
     $putPolicy->Expires = 60 * 30;
     $putPolicy->SaveKey = $preKey . '$(etag)' . $suffix;
     if ($returnUrl !== null) {
         $putPolicy->ReturnUrl = $returnUrl;
     }
     if ($returnBody !== null) {
         $putPolicy->ReturnBody = json_encode($returnBody);
     }
     if ($pipeline !== null) {
         $putPolicy->PersistentPipeline = $pipeline;
     }
     if ($persistentOps !== null && $persistentUrl !== null) {
         $putPolicy->PersistentOps = $persistentOps;
         $putPolicy->PersistentNotifyUrl = $persistentUrl;
     }
     $upToken = $putPolicy->Token(null);
     return $upToken;
 }
Exemple #17
0
 if (!empty($_SESSION['uid'])) {
     $uid = $_SESSION['uid'];
     $time = time();
     require_once '../qiniu/io.php';
     require_once '../qiniu/rs.php';
     $qiniu = (include '../qiniu/qiniu.php');
     require_once '../connect/PdoConnect.class.php';
     $db = (include '../connect/dbconfig.php');
     $accessKey = $qiniu['accessKey'];
     $secretKey = $qiniu['secretKey'];
     $bucket = $qiniu['bucket'];
     //2
     $pdo = new PDO_CON($db['dbtype'], $db['host'], $db['user'], $db['pasw'], $db['dbname']);
     $conn = $pdo->get_conId();
     $newname = time() . rand(10000, 99999) . '.jpg';
     Qiniu_SetKeys($accessKey, $secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($bucket);
     $upToken = $putPolicy->Token(null);
     list($ret, $err) = Qiniu_Put($upToken, $newname, file_get_contents($tmp_name), null);
     file_put_contents('./log', "ok", FILE_APPEND);
     $sql = "insert into ws_photo(picture,userid,time) values('{$newname}',{$uid},{$time})";
     $pdo->ExceSQL($sql, $conn);
 }
 /**
  * save to qiniu end
  */
 //		//移动文件
 //		$file_path = $save_path . $new_file_name;
 //		@chmod($file_path, 0644);//修改目录权限(Linux)
 //		if (move_uploaded_file($tmp_name, $file_path) === false) {//开始移动
 //			exit("返回错误: 上传文件失败。($file_name)");
<?php

header("Content-Type: application/json; charset=utf-8");
require_once "../../qiniu/rs.php";
require_once "../../config.php";
Qiniu_SetKeys($Qiniu_AccessKey, $Qiniu_SecretKey);
$putPolicy = new Qiniu_RS_PutPolicy($Qiniu_Public_Bucket);
//json format
$returnBody = array("key" => "\$(key)", "hash" => "\$(hash)", "bucket" => "\$(bucket)", "exParam1" => "\$(x:exParam1)", "exParam2" => "\$(x:exParam2)");
$returnBody = json_encode($returnBody);
$putPolicy->ReturnBody = $returnBody;
$token = $putPolicy->Token(null);
$respBody = array("uptoken" => $token);
$respBody = json_encode($respBody);
echo $respBody;
/**
 * 远程抓取
 * @param $uri
 * @param $config
 */
function getRemoteImage($uri, $config)
{
    //忽略抓取时间限制
    set_time_limit(0);
    //ue_separate_ue  ue用于传递数据分割符号
    $imgUrls = explode("ue_separate_ue", $uri);
    $tmpNames = array();
    foreach ($imgUrls as $imgUrl) {
        //http开头验证
        if (strpos($imgUrl, "http") !== 0) {
            array_push($tmpNames, "error");
            continue;
        }
        //获取请求头
        $heads = get_headers($imgUrl);
        //死链检测
        if (!(stristr($heads[0], "200") && stristr($heads[0], "OK"))) {
            array_push($tmpNames, "error");
            continue;
        }
        //格式验证(扩展名验证和Content-Type验证)
        $fileType = strtolower(strrchr($imgUrl, '.'));
        if (!in_array($fileType, $config['allowFiles']) || stristr($heads['Content-Type'], "image")) {
            array_push($tmpNames, "error");
            continue;
        }
        //打开输出缓冲区并获取远程图片
        ob_start();
        $context = stream_context_create(array('http' => array('follow_location' => false)));
        //请确保php.ini中的fopen wrappers已经激活
        readfile($imgUrl, false, $context);
        $img = ob_get_contents();
        ob_end_clean();
        //大小验证
        $uriSize = strlen($img);
        //得到图片大小
        $allowSize = 1024 * $config['maxSize'];
        if ($uriSize > $allowSize) {
            array_push($tmpNames, "error");
            continue;
        }
        //创建保存位置
        $savePath = $config['savePath'];
        if (!file_exists($savePath)) {
            mkdir("{$savePath}", 0777);
        }
        //写入文件
        //$tmpName = $savePath . rand( 1 , 10000 ) . time() . strrchr( $imgUrl , '.' );
        //            try {
        //                $fp2 = @fopen( $tmpName , "a" );
        //                fwrite( $fp2 , $img );
        //                fclose( $fp2 );
        //                array_push( $tmpNames ,  $tmpName );
        //            } catch ( Exception $e ) {
        //                array_push( $tmpNames , "error" );
        //            }
        /***
         * 保存图片文件到七牛
         * 1.引入七牛类文件
         * 2.引入七牛配置文件
         */
        require_once '../../qiniu/io.php';
        require_once '../../qiniu/rs.php';
        $qiniu = (include '../../qiniu/qiniu.php');
        $newname = time() . rand(10000, 99999) . '.jpg';
        $accessKey = $qiniu['accessKey'];
        $secretKey = $qiniu['secretKey'];
        $bucket = $qiniu['bucket'];
        Qiniu_SetKeys($accessKey, $secretKey);
        if (!is_object($putPolicy)) {
            $putPolicy = new Qiniu_RS_PutPolicy($bucket);
        }
        $upToken = $putPolicy->Token(null);
        list($ret, $err) = Qiniu_Put($upToken, $newname, $img, null);
        /**
         * 为blog中生成一条记录 返回blogid 插入到images中
         */
        if (!isset($_SESSION)) {
            session_start();
        }
        if (!empty($_SESSION['uid'])) {
            require_once '../../connect/PdoConnect.class.php';
            $db = (include '../../connect/dbconfig.php');
            $pdo = new PDO_CON($db['dbtype'], $db['host'], $db['user'], $db['pasw'], $db['dbname']);
            $conn = $pdo->get_conId();
            /**
             * 此处数据库中表名是写的死的   若有改变  请直接替换
             * 博文与图片是以一对多的关系   用session机制限制一对一关系
             * 一次发布文章动作成功后  注销session['blogid']
             */
            $uid = $_SESSION['uid'];
            if (empty($_SESSION['blogid'])) {
                $time = time();
                $sql = "insert into ws_blog(userid,time) values({$uid},{$time})";
                $res = $pdo->ExceSQL($sql, $conn);
                if ($res) {
                    $sql = "select id from ws_blog where userid = {$uid} and time = {$time} ";
                    $res = $pdo->ExceSQL($sql, $conn);
                    $id = $res[0]['id'];
                }
                $_SESSION['blogid'] = $id;
            } else {
                $id = $_SESSION['blogid'];
            }
            /**
             * 保存图片到image表
             */
            $sql = "insert into ws_image(blogid,image) value({$id},'{$newname}')";
            $res = $pdo->ExceSQL($sql, $conn);
        }
        /**
         * 插入到image表完成
         */
        //返回图片地址  编辑器中引用改地址
        //$url = "http://".$qiniu['bucket'].".".$qiniu['domain']."/".$newname."?".'imageMogr2/thumbnail/540x335!';
        //$url = "http://".$qiniu['bucket'].".".$qiniu['domain']."/".$newname;
        $url = $qiniu['resurl'] . $newname;
    }
    /**
     * 返回数据格式
     * {
     *   'url'   : '新地址一ue_separate_ue新地址二ue_separate_ue新地址三',
     *   'srcUrl': '原始地址一ue_separate_ue原始地址二ue_separate_ue原始地址三',
     *   'tip'   : '状态提示'
     * }
     */
    echo "{'url':'" . $url . "','tip':'远程图片抓取成功!','srcUrl':'" . $uri . "'}";
}
Exemple #20
0
 /**
  * 上传文件到七牛
  * @param string $file 源文件  
  * @param string $upname 上传后的文件名  
  * @param string $bucket 七牛上传的位置 
  */
 public static function upFiletoQiniu($file, $upname, $bucket)
 {
     $path = Yii::getPathOfAlias('application');
     require_once $path . "/vendors/qiniu/rs.php";
     require_once $path . "/vendors/qiniu/io.php";
     $qiniu_config = Yii::app()->params['qiniuConfig'];
     $accessKey = $qiniu_config['ak'];
     $secretKey = $qiniu_config['sk'];
     Qiniu_SetKeys($accessKey, $secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($bucket);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $upname, $file, $putExtra);
     if ($err !== null) {
         return false;
     } else {
         return true;
     }
 }
Exemple #21
0
/**
 * @param $upload
 */
function CloudStorage_Del(&$upload)
{
    global $zbp;
    $bucket = $zbp->Config('CloudStorage')->CS_Bucket;
    switch ($upload->Metas->CS_Tpye) {
        case '1':
            define('OSS_ACCESS_ID', $zbp->Config('CloudStorage')->CS_Ali_KeyID);
            //ACCESS_ID
            define('OSS_ACCESS_KEY', $zbp->Config('CloudStorage')->CS_Ali_KeySecret);
            //ACCESS_KEY
            require_once dirname(__FILE__) . '/api/oss/sdk.class.php';
            $os_service = new ALIOSS();
            $os_service->set_debug_mode(FALSE);
            $object = str_replace("http://" . $bucket . ".oss.aliyuncs.com/", '', $upload->Metas->CS_URL);
            $os_service->delete_object($bucket, $object);
            break;
        case '2':
            require_once dirname(__FILE__) . '/api/qiniu/io.php';
            require_once dirname(__FILE__) . '/api/qiniu/rs.php';
            $accessKey = $zbp->Config('CloudStorage')->CS_QNiu_KeyID;
            $secretKey = $zbp->Config('CloudStorage')->CS_QNiu_KeySecret;
            Qiniu_SetKeys($accessKey, $secretKey);
            $client = new Qiniu_MacHttpClient(null);
            $object = str_replace("http://" . $bucket . ".u.qiniudn.com/", '', $upload->Metas->CS_URL);
            Qiniu_RS_Delete($client, $bucket, $object);
            break;
        case '3':
            define('BCS_AK', $zbp->Config('CloudStorage')->CS_Baidu_KeyID);
            //AK 公钥
            define('BCS_SK', $zbp->Config('CloudStorage')->CS_Baidu_KeySecret);
            //SK 私钥
            require_once dirname(__FILE__) . '/api/bcs/bcs.class.php';
            $baidu_bcs = new BaiduBCS();
            $object = str_replace("http://bcs.duapp.com/" . $bucket, '', $upload->Metas->CS_URL);
            $baidu_bcs->delete_object($bucket, $object);
            break;
        default:
            break;
    }
    return true;
    $GLOBALS['Filter_Plugin_Upload_DelFile']['CloudStorage_Del'] = PLUGIN_EXITSIGNAL_RETURN;
}
    $bucketName = $row3['p_bucketname'];
    $ak = $row3['p_ak'];
    $sk = $row3['p_sk'];
}
function deleteShare($key1, $con)
{
    $shengji = "update sd_file set cishuo = '1' where key1 = '{$key1}'";
    mysqli_query($con, $shengji);
    $shanchu = "delete from sd_ss where filekey = '{$key1}'";
    $shanchu1 = "delete from sd_sskey where filekey = '{$key1}'";
    mysqli_query($con, $shanchu);
    mysqli_query($con, $shanchu1);
}
switch ($policyType) {
    case 'qiniu':
        Qiniu_SetKeys($ak, $sk);
        $client = new Qiniu_MacHttpClient(null);
        $err = Qiniu_RS_Delete($client, $bucketName, $ming);
        if ($err !== null) {
            echo "bad.删除失败";
        } else {
            echo "ok.删除成功";
            deleteShare($key1, $con);
        }
        break;
    case 'local':
        $deleteAction = @unlink(dirname(dirname(__FILE__)) . "/" . $fileDir . "/" . $ming);
        if ($deleteAction) {
            echo "ok.删除成功";
            deleteShare($key1, $con);
        } else {
 public function imageThumb($filename, $mode, $width, $height)
 {
     $this->setBucketAndKey($filename);
     Qiniu_SetKeys($this->accessKey, $this->secretKey);
     $domain = $this->getDomain();
     $baseUrl = Qiniu_RS_MakeBaseUrl($domain, $this->key);
     $imgView = new \Qiniu_ImageView();
     $imgView->Mode = $mode;
     $imgView->Width = $width;
     $imgView->Height = $height;
     $imgViewUrl = $imgView->MakeRequest($baseUrl);
     return $imgViewUrl;
 }
Exemple #24
0
define('LIB_DIR', ROOT_DIR . 'lib' . DIRECTORY_SEPARATOR);
define('QBOX_SDK_DIR', LIB_DIR . 'qiniu' . DIRECTORY_SEPARATOR);
/**
 * 加载配置文件
 */
require_once LIB_DIR . 'config.php';
require_once LIB_DIR . 'helper.php';
require_once LIB_DIR . 'pdo.class.php';
require_once QBOX_SDK_DIR . 'rs.php';
/**
 * 设置错误报告级别
 */
error_reporting($config['error']['reporting']);
/**
 * 初始化数据库连接句柄
 */
$db = Core_Db::getInstance($config["db"]);
/**
 * 配置七牛云存储密钥信息
 */
$qiniu_access_key = $config["qbox"]["access_key"];
$qiniu_secret_key = $config["qbox"]["secret_key"];
#$qiniu_up_host = $config['qbox']['up_host'];
$bucket = $config["qbox"]["bucket"];
Qiniu_SetKeys($qiniu_access_key, $qiniu_secret_key);
$putPolicy = new Qiniu_RS_PutPolicy($bucket);
$putPolicy->CallbackUrl = $config['qbox']['callback_url'];
$putPolicy->CallbackBody = $config['qbox']['callback_body'];
$upToken = $putPolicy->Token(null);
$client = new Qiniu_MacHttpClient(null);
$domain = $config['qbox']['domain'];
 public function actionDelmv($id)
 {
     Yii::import('application.vendors.*');
     require_once 'Qiniu/rs.php';
     require_once 'Qiniu/io.php';
     $bucket = Yii::app()->params['bucket'];
     $accessKey = Yii::app()->params['accessKey'];
     $secretKey = Yii::app()->params['secretKey'];
     $mvModel = new Mv();
     $mvInfo = $mvModel->findByPk($id);
     if ($mvInfo != NULL) {
         Qiniu_SetKeys($accessKey, $secretKey);
         $client = new Qiniu_MacHttpClient(null);
         $err = Qiniu_RS_Delete($client, $bucket, $mvInfo['mv']);
     }
     //上传业务数据库中数据
     if ($mvModel->deleteByPk($id)) {
         Yii::app()->user->setFlash('delmvstatus', 'YES,删除视频成功 :)');
     } else {
         Yii::app()->user->setFlash('delmvstatus', 'Sorry,系统出错,删除视频失败 :(');
     }
     $this->redirect(array("imv"));
 }
Exemple #26
0
function deleteQiNiu($filePath)
{
    //这里写入七牛的空间名
    $bucket = "1111";
    //$bucket = "gavinwen-topic";
    $key1 = basename($filePath);
    //这里写入七牛的accessKey和secretKey
    $accessKey = 'sVv4Xk-11';
    $secretKey = '333-11222';
    Qiniu_SetKeys($accessKey, $secretKey);
    $client = new Qiniu_MacHttpClient(null);
    $err = Qiniu_RS_Delete($client, $bucket, $key1);
    if ($err !== null) {
        return false;
    } else {
        return true;
    }
}
Exemple #27
0
 /**
  * Perform the file upload
  *
  * @return	bool
  */
 public function do_upload($field = 'userfile', $qiniu = FALSE)
 {
     // Is $_FILES[$field] set? If not, no reason to continue.
     if (!isset($_FILES[$field])) {
         $this->set_error('upload_no_file_selected');
         return FALSE;
     }
     // Is the upload path valid?
     if (!$this->validate_upload_path()) {
         // errors will already be set by validate_upload_path() so just return FALSE
         return FALSE;
     }
     // Was the file able to be uploaded? If not, determine the reason why.
     if (!is_uploaded_file($_FILES[$field]['tmp_name'])) {
         $error = !isset($_FILES[$field]['error']) ? 4 : $_FILES[$field]['error'];
         switch ($error) {
             case 1:
                 // UPLOAD_ERR_INI_SIZE
                 $this->set_error('upload_file_exceeds_limit');
                 break;
             case 2:
                 // UPLOAD_ERR_FORM_SIZE
                 $this->set_error('upload_file_exceeds_form_limit');
                 break;
             case 3:
                 // UPLOAD_ERR_PARTIAL
                 $this->set_error('upload_file_partial');
                 break;
             case 4:
                 // UPLOAD_ERR_NO_FILE
                 $this->set_error('upload_no_file_selected');
                 break;
             case 6:
                 // UPLOAD_ERR_NO_TMP_DIR
                 $this->set_error('upload_no_temp_directory');
                 break;
             case 7:
                 // UPLOAD_ERR_CANT_WRITE
                 $this->set_error('upload_unable_to_write_file');
                 break;
             case 8:
                 // UPLOAD_ERR_EXTENSION
                 $this->set_error('upload_stopped_by_extension');
                 break;
             default:
                 $this->set_error('upload_no_file_selected');
                 break;
         }
         return FALSE;
     }
     // Set the uploaded data as class variables
     $this->file_temp = $_FILES[$field]['tmp_name'];
     $this->file_size = $_FILES[$field]['size'];
     $this->_file_mime_type($_FILES[$field]);
     $this->file_type = preg_replace("/^(.+?);.*\$/", "\\1", $this->file_type);
     $this->file_type = strtolower(trim(stripslashes($this->file_type), '"'));
     $this->file_name = $this->_prep_filename($_FILES[$field]['name']);
     $this->file_ext = $this->get_extension($this->file_name);
     $this->client_name = $this->file_name;
     $this->fileMD5 = md5_file($this->file_temp);
     // Is the file type allowed to be uploaded?
     if (!$this->is_allowed_filetype()) {
         $this->set_error('upload_invalid_filetype');
         return FALSE;
     }
     // if we're overriding, let's now make sure the new name and type is allowed
     if ($this->_file_name_override != '') {
         $this->file_name = $this->_prep_filename($this->_file_name_override);
         // If no extension was provided in the file_name config item, use the uploaded one
         if (strpos($this->_file_name_override, '.') === FALSE) {
             $this->file_name .= $this->file_ext;
         } else {
             $this->file_ext = $this->get_extension($this->_file_name_override);
         }
         if (!$this->is_allowed_filetype(TRUE)) {
             $this->set_error('upload_invalid_filetype');
             return FALSE;
         }
     }
     // Convert the file size to kilobytes
     if ($this->file_size > 0) {
         $this->file_size = round($this->file_size / 1024, 2);
     }
     // Is the file size within the allowed maximum?
     if (!$this->is_allowed_filesize()) {
         $this->set_error('upload_invalid_filesize');
         return FALSE;
     }
     // Are the image dimensions within the allowed size?
     // Note: This can fail if the server has an open_basdir restriction.
     if (!$this->is_allowed_dimensions()) {
         $this->set_error('upload_invalid_dimensions');
         return FALSE;
     }
     // Sanitize the file name for security
     $this->file_name = $this->clean_file_name($this->file_name);
     // Truncate the file name if it's too long
     if ($this->max_filename > 0) {
         $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename);
     }
     // Remove white spaces in the name
     if ($this->remove_spaces == TRUE) {
         $this->file_name = preg_replace("/\\s+/", "_", $this->file_name);
     }
     /*
      * Validate the file name
      * This function appends an number onto the end of
      * the file if one with the same name already exists.
      * If it returns false there was a problem.
      */
     $this->orig_name = $this->file_name;
     if ($this->overwrite == FALSE) {
         $this->file_name = $this->set_filename($this->upload_path, $this->file_name);
         if ($this->file_name === FALSE) {
             return FALSE;
         }
     }
     /*
      * Run the file through the XSS hacking filter
      * This helps prevent malicious code from being
      * embedded within a file.  Scripts can easily
      * be disguised as images or other file types.
      */
     if ($this->xss_clean) {
         if ($this->do_xss_clean() === FALSE) {
             $this->set_error('upload_unable_to_write_file');
             return FALSE;
         }
     }
     /*
      * Move the file to the final destination
      * To deal with different server configurations
      * we'll attempt to use copy() first.  If that fails
      * we'll use move_uploaded_file().  One of the two should
      * reliably work in most environments
      */
     //$fileMD5 = md5_file($this->file_temp);
     $profix = substr($this->fileMD5, 0, 2);
     $upload_old = $this->upload_path;
     $this->upload_path = $this->upload_path . $profix . "/";
     if (!file_exists($this->upload_path)) {
         mkdir($this->upload_path);
         chmod($this->upload_path, 0777);
     }
     if ($qiniu) {
         //加载七牛签名SDK
         require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'third_party' . DIRECTORY_SEPARATOR . 'qiniu' . DIRECTORY_SEPARATOR . 'io.php';
         require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'third_party' . DIRECTORY_SEPARATOR . 'qiniu' . DIRECTORY_SEPARATOR . 'rs.php';
         $key = JY_getUploadFileName("10086");
         $accessKey = 'pU2VbLy6emWXs5x8Kxy2ZIKFtCHID-ghDimXM9tl';
         $secretKey = '3N2Ngow0rsEFiJzK6EoHPljza3iP55GtTwsv2WyF';
         Qiniu_SetKeys($accessKey, $secretKey);
         $putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
         $upToken = $putPolicy->Token(null);
         $putExtra = new Qiniu_PutExtra();
         $putExtra->Crc32 = 1;
         list($ret, $err) = Qiniu_PutFile($upToken, $key, $this->file_temp, $putExtra);
         if ($err !== null) {
             $this->set_error('upload_destination_error');
         } else {
             $this->qiniuData = $ret;
         }
     } else {
         if (!@copy($this->file_temp, $this->upload_path . $this->file_name)) {
             if (!@move_uploaded_file($this->file_temp, $this->upload_path . $this->file_name)) {
                 $this->set_error('upload_destination_error');
                 return FALSE;
             }
         }
     }
     //还原upload目录
     $this->upload_path = $upload_old;
     /*
      * Set the finalized image dimensions
      * This sets the image width/height (assuming the
      * file was an image).  We use this information
      * in the "data" function.
      */
     $this->set_image_properties($this->upload_path . $this->file_name);
     return TRUE;
 }
Exemple #28
0
 public function __construct($bucket, $accessKey, $accessSecret, $domain = null)
 {
     $this->bucket = $bucket;
     Qiniu_SetKeys($accessKey, $accessSecret);
     $this->domain = $domain === null ? $this->bucket . '.qiniudn.com' : $domain;
 }
Exemple #29
0
 public static function setKeyContent($key, $content = null)
 {
     if (W2Qiniu::getKeyContent($key) != null) {
         if (!W2Qiniu::deleteFile($key)) {
             throw new Exception('无法删除文件', 1);
         }
     }
     Qiniu_SetKeys(W2Config::$Qiniu_accessKey, W2Config::$Qiniu_secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy(W2Config::$Qiniu_bucket);
     $upToken = $putPolicy->Token(null);
     list($ret, $err) = Qiniu_Put($upToken, $key, $content, null);
     if ($err !== null) {
         if (defined('IS_SQL_PRINT') && IS_SQL_PRINT) {
             var_dump($err);
         }
         return false;
     } else {
         return true;
     }
 }
Exemple #30
0
function wpjam_get_qiniutek_client()
{
    $wpjam_qiniutek = get_option('wpjam-qiniutek');
    if (!class_exists('Qiniu_MacHttpClient')) {
        require_once WP_CONTENT_DIR . "/plugins/wpjam-qiniu/sdk/rs.php";
    }
    Qiniu_SetKeys($wpjam_qiniutek['access'], $wpjam_qiniutek['secret']);
    $qiniutek_client = new Qiniu_MacHttpClient(null);
    return $qiniutek_client;
}