示例#1
0
文件: Etag.php 项目: itliuchang/test
 public static function sum($filename)
 {
     $fhandler = fopen($filename, 'r');
     $err = error_get_last();
     if ($err !== null) {
         return array(null, $err);
     }
     $fstat = fstat($fhandler);
     $fsize = $fstat['size'];
     if ($fsize == 0) {
         fclose($fhandler);
         return array('Fto5o-5ea0sNMlW_75VgGJCv2AcJ', null);
     }
     $blockCnt = self::blockCount($fsize);
     $sha1Buf = array();
     if ($blockCnt <= 1) {
         array_push($sha1Buf, 0x16);
         $fdata = fread($fhandler, Config::BLOCK_SIZE);
         if ($err !== null) {
             fclose($fhandler);
             return array(null, $err);
         }
         list($sha1Code, ) = calSha1($fdata);
         $sha1Buf = array_merge($sha1Buf, $sha1Code);
     } else {
         array_push($sha1Buf, 0x96);
         $sha1BlockBuf = array();
         for ($i = 0; $i < $blockCnt; $i++) {
             $fdata = fread($fhandler, Config::BLOCK_SIZE);
             list($sha1Code, $err) = self::calcSha1($fdata);
             if ($err !== null) {
                 fclose($fhandler);
                 return array(null, $err);
             }
             $sha1BlockBuf = array_merge($sha1BlockBuf, $sha1Code);
         }
         $tmpData = self::packArray('C*', $sha1BlockBuf);
         list($sha1Final, ) = self::calcSha1($tmpData);
         $sha1Buf = array_merge($sha1Buf, $sha1Final);
     }
     $etag = Functions::base64_urlSafeEncode(self::packArray('C*', $sha1Buf));
     return array($etag, null);
 }
示例#2
0
 /**
  * 从指定URL抓取资源,并将该资源存储到指定空间中
  *
  * @param $url        指定的URL
  * @param $bucket     目标资源空间
  * @param $key        目标资源文件名
  *
  * @return array    包含已拉取的文件信息。
  *                         成功时:  [
  *                                          [
  *                                              "hash" => "<Hash string>",
  *                                              "key" => "<Key string>"
  *                                          ],
  *                                          null
  *                                  ]
  *
  *                         失败时:  [
  *                                          null,
  *                                         ext/qiniu/Http/Error
  *                                  ]
  * @link  http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html
  */
 public function fetch($url, $bucket, $key)
 {
     $resource = Functions::base64_urlSafeEncode($url);
     $to = Functions::entry($bucket, $key);
     $path = '/fetch/' . $resource . '/to/' . $to;
     return $this->ioPost($path);
 }
示例#3
0
文件: Auth.php 项目: itliuchang/test
 public function signWithData($data)
 {
     $data = Functions::base64_urlSafeEncode($data);
     return $this->sign($data) . ':' . $data;
 }
示例#4
0
 private function fileUrl()
 {
     $url = $this->host . '/mkfile/' . $this->size;
     $url .= '/mimeType/' . Functions::base64_urlSafeEncode($this->mime);
     if ($this->key != null) {
         $url .= '/key/' . Functions::base64_urlSafeEncode($this->key);
     }
     if (!empty($this->params)) {
         foreach ($this->params as $key => $value) {
             $val = Functions::base64_urlSafeEncode($value);
             $url .= "/{$key}/{$val}";
         }
     }
     return $url;
 }