public function buildUptoken($bucket, $key)
 {
     $accessKey = C('QINIU_ACCESS_KEY');
     $secretKey = C('QINIU_SECRET_KEY');
     Qiniu_setKeys($accessKey, $secretKey);
     $putPolicy = new \Qiniu_RS_PutPolicy($bucket . ':' . $key);
     $upToken = $putPolicy->Token(null);
     echo $upToken;
 }
Example #2
0
 function __construct($config = array())
 {
     global $_G;
     $this->set_error(0);
     $this->config = !$config ? getglobal('setting/ftp') : $config;
     $this->enabled = false;
     if (empty($this->config['on']) || empty($this->config['host']) && empty($_G['config']['extend']['storage']['curstorage'])) {
         $this->set_error(FTP_ERR_CONFIG_OFF);
     } else {
         if ($_G['config']['extend']['storage']['curstorage'] != '') {
             $this->curstorage = $_G['config']['extend']['storage']['curstorage'];
             $this->config_ext = $_G['config']['extend']['storage'][$this->curstorage];
             C::import('storage/' . $this->curstorage, 'vendor', true, true);
             switch ($this->curstorage) {
                 case 'upyun':
                     $this->curobj = new UpYun($this->config_ext['bucket'], $this->config_ext['username'], $this->config_ext['password']);
                     break;
                 case 'aliyun':
                     $this->curobj = new ALIOSS($this->config_ext['access_id'], $this->config_ext['access_key'], $this->config_ext['hostname']);
                     $this->curobj->set_debug_mode(FALSE);
                     break;
                 case 'qiniu':
                     $GLOBALS['QINIU_UP_HOST'] = 'http://up.qiniu.com';
                     $GLOBALS['QINIU_RS_HOST'] = 'http://rs.qbox.me';
                     $GLOBALS['QINIU_RSF_HOST'] = 'http://rsf.qbox.me';
                     Qiniu_setKeys($this->config_ext['accesskey'], $this->config_ext['secretkey']);
                     $this->curobj = true;
                     break;
                 case 'grand':
                     break;
             }
             !empty($this->curobj) && ($this->enabled = true);
             return true;
         }
         $this->func = $this->config['ssl'] && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
         if ($this->func == 'ftp_connect' && !function_exists('ftp_connect')) {
             $this->set_error(FTP_ERR_SERVER_DISABLED);
         } else {
             $this->config['host'] = discuz_ftp::clear($this->config['host']);
             $this->config['port'] = intval($this->config['port']);
             $this->config['ssl'] = intval($this->config['ssl']);
             $this->config['username'] = discuz_ftp::clear($this->config['username']);
             $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
             $this->config['timeout'] = intval($this->config['timeout']);
             $this->enabled = true;
         }
     }
 }
Example #3
0
function picThumb($accessKey, $secretKey, $key1, $width, $height)
{
    // --------------------------压缩图片 start
    //    require_once('qiniu/rs.php');
    require_once 'qiniu/fop.php';
    $key1 = $key1;
    $domain = 'zhaoliwu.qiniudn.com';
    Qiniu_setKeys($accessKey, $secretKey);
    //$baseUrl 就是您要访问资源的地址
    $baseUrl = Qiniu_RS_MakeBaseUrl($domain, $key1);
    $getPolicy = new Qiniu_RS_GetPolicy();
    $imgView = new Qiniu_ImageView();
    $imgView->Mode = 1;
    $imgView->Width = $width;
    $imgView->Height = $height;
    //生成fopUrl
    $imgViewUrl = $imgView->MakeRequest($baseUrl);
    //对fopUrl 进行签名,生成privateUrl。 公有bucket 此步可以省去。
    $imgViewPrivateUrl = $getPolicy->MakeRequest($imgViewUrl, null);
    echo "\n\n====> imageView privateUrl: \n";
    echo $imgViewPrivateUrl . "\n";
    // ------------------------------------ end
}
 /**
  * $filename 七牛可以手动填写路径
  */
 function sendToQiniu($path, $filename)
 {
     Qiniu_setKeys(self::$qiniuAccessKey, self::$qiniuSecretKey);
     $qiniu = new Qiniu_MacHttpClient(null);
     $putPolicy = new Qiniu_RS_PutPolicy(self::$bucket);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $filename, $path, $putExtra);
     if ($err) {
         return array('code' => -2, 'msg' => $err);
     } else {
         $file = $ret['key'];
         $domain = self::$bucket . '.qiniudn.com';
         $baseUrl = Qiniu_RS_MakeBaseUrl($domain, $file);
         $private = false;
         if ($private) {
             $getPolicy = new Qiniu_RS_GetPolicy();
             $baseUrl = $getPolicy->MakeRequest($baseUrl, null);
         }
         return array('code' => 0, 'msg' => $baseUrl);
     }
 }
Example #5
0
        ?>
" size="60"/>
	</td>
  </tr>

  <tr>
     <th scope="row"></th>
	 <td>
	   <p><?php 
        _e('If the settings are correct, will upload a image to your Qiniu Bucket and appear here.', 'wp-autopost');
        ?>
</p>
  <?php 
        if ($Qiniu['domain'] != '' && $Qiniu['bucket'] != '' && $Qiniu['access_key'] != '' && $Qiniu['secret_key'] != '') {
            $upload_image = dirname(__FILE__) . '/images/watermark.png';
            Qiniu_setKeys($Qiniu['access_key'], $Qiniu['secret_key']);
            list($ret, $err) = Qinniu_upload_to_bucket($Qiniu['bucket'], $upload_image, 'wp-autopost-logo.png');
            if ($err !== null) {
                echo '<div style="background-color:#ffebe8;border-color:#cc0000;border-style:solid;border-width:1px;padding:10px;">';
                //var_dump($err);
                echo $err->Err;
                echo '</div>';
                $Qiniu['set_ok'] = 0;
                update_option('wp-autopost-qiniu-options', $Qiniu);
            } else {
                $Qiniu['set_ok'] = 1;
                update_option('wp-autopost-qiniu-options', $Qiniu);
                $baseUrl = Qiniu_RS_MakeBaseUrl($Qiniu['domain'], $ret['key']);
                echo '<div class="view_img"><img src=' . $baseUrl . ' /></div>';
                echo __('The image URL', 'wp-autopost') . ' : <a href="' . $baseUrl . '" target="_blank">' . $baseUrl . '</a>';
            }
Example #6
0
# @gist key1
$key1 = 'file_name_1';
# @endgist
# @gist key2
$key2 = 'file_name_2';
# @endgist
# @gist file
$file = 'docs/gist/logo.jpg';
# @endgist
# @gist domain
$domain = 'phpsdk.qiniudn.com';
# @endgist
# @gist set_keys
$accessKey = '<YOUR_ACCESS_KEY>';
$secretKey = '<YOUR_SECRET_KEY>';
Qiniu_setKeys($accessKey, $secretKey);
# @endgist
# @gist mac_client
$client = new Qiniu_MacHttpClient(null);
# @endgist
Qiniu_RS_Delete($client, $bucket, $key1);
Qiniu_RS_Delete($client, $bucket, $key2);
//------------------------------------io-----------------------------------------
# @gist putpolicy
$putPolicy = new Qiniu_RS_PutPolicy($bucket);
$upToken = $putPolicy->Token(null);
# @endgist
# @gist put
list($ret, $err) = Qiniu_Put($upToken, $key1, 'Qiniu Storage!', null);
echo "\n\n====> Qiniu_Put result: \n";
if ($err !== null) {
Example #7
0
 /**
  * Delete file from qiniu cloud
  * @param  string $fileName file name
  * @param  string $privateBucket  whether store file in private bucket
  */
 public function deleteFile($fileName, $privateBucket = false)
 {
     if ($privateBucket) {
         $this->change2Private();
     }
     Qiniu_setKeys(QINIU_ACCESS_KEY, QINIU_SECRET_KEY);
     $client = new \Qiniu_MacHttpClient(null);
     return Qiniu_RS_Delete($client, $this->bucket, $fileName);
 }
Example #8
0
 /**
  * 调取七牛许可
  * 
  * @access public
  * @return void
  */
 public static function qiniuset($accesskey, $secretkey)
 {
     require_once "cloud/qiniu/io.php";
     require_once "cloud/qiniu/rs.php";
     require_once "cloud/qiniu/rsf.php";
     Qiniu_setKeys($accesskey, $secretkey);
 }
Example #9
0
 public function authorize()
 {
     global $_G, $_GET, $clouds;
     if (empty($_G['uid'])) {
         dsetcookie('_refer', rawurlencode(BASESCRIPT . '?mod=connect&op=oauth&bz=qiniu'));
         showmessage('to_login', '', array(), array('showmsg' => true, 'login' => 1));
     }
     if (submitcheck('qiniusubmit')) {
         $access_id = $_GET['access_id'];
         $access_key = $_GET['access_key'];
         $hostname = $_GET['hostname'];
         $bucket = $_GET['bucket'];
         if (!$access_id || !$access_key) {
             showmessage('please input qiniu AK and SK', dreferer());
         }
         if (!$bucket || !$hostname) {
             showmessage('请设置bucket名称和访问域名', dreferer());
         }
         Qiniu_setKeys($access_id, $access_key);
         try {
             $putPolicy = new Qiniu_RS_PutPolicy($bucket);
             $upToken = $putPolicy->Token(null);
             $putExtra = new Qiniu_PutExtra();
             $putExtra->Crc32 = 1;
             $file = DZZ_ROOT . './dzz/images/b.gif';
             list($ret, $err) = Qiniu_PutFile($upToken, 'b.gif', $file, $putExtra);
             if ($err) {
                 showmessage($err->Code . ':' . $err->Err, dreferer());
             }
             //测试读取图片
             $baseUrl = Qiniu_RS_MakeBaseUrl($hostname, 'b.gif');
             $getPolicy = new Qiniu_RS_GetPolicy();
             $privateUrl = $getPolicy->MakeRequest($baseUrl, null);
             if (!@getimagesize($privateUrl)) {
                 showmessage('测试读取失败,请检查您设置的访问域名是否正确', dreferer());
             }
         } catch (Exception $e) {
             showmessage($e->getMessage(), dreferer());
         }
         //删除测试图片
         $client = new Qiniu_MacHttpClient(null);
         Qiniu_RS_Delete($client, $bucket, 'b.gif');
         $type = 'qiniu';
         $uid = defined('IN_ADMIN') ? 0 : $_G['uid'];
         $setarr = array('uid' => $uid, 'access_id' => $access_id, 'access_key' => authcode($access_key, 'ENCODE', $type), 'bz' => $type, 'bucket' => $bucket, 'hostname' => $hostname, 'dateline' => TIMESTAMP);
         if ($id = DB::result_first("select id from " . DB::table(self::T) . " where uid='{$uid}' and access_id='{$access_id}' and bucket='{$bucket}'")) {
             DB::update(self::T, $setarr, "id ='{$id}'");
         } else {
             $id = DB::insert(self::T, $setarr, 1);
         }
         if (defined('IN_ADMIN')) {
             $setarr = array('name' => $clouds[$type]['name'] . ':' . ($bucket ? $bucket : cutstr($access_id, 4, '')), 'bz' => $type, 'isdefault' => 0, 'dname' => self::T, 'did' => $id, 'dateline' => TIMESTAMP);
             if (!DB::result_first("select COUNT(*) from %t where did=%d and dname=%s ", array('local_storage', $id, self::T))) {
                 C::t('local_storage')->insert($setarr);
             }
             showmessage('do_success', BASESCRIPT . '?mod=cloud&op=space');
         } else {
             showmessage('do_success', BASESCRIPT . '?mod=connect');
         }
     } else {
         include template('oauth_qiniu');
     }
 }