This page lists files in the current directory. You can view content, get download/execute commands for Wget, Curl, or PowerShell, or filter the list using wildcards (e.g., `*.sh`).
wget 'https://sme10.lists2.roe3.org/kodbox/app/sdks/IO/qiniu/Qiniu/Storage/ArgusManager.php'
<?php
namespace Qiniu\Storage;
use Qiniu\Auth;
use Qiniu\Config;
use Qiniu\Zone;
use Qiniu\Http\Client;
use Qiniu\Http\Error;
/**
* 主要涉及了鉴黄接口的实现,具体的接口规格可以参考
*
* @link https://developer.qiniu.com/dora/manual/3674/kodo-product-introduction
*/
final class ArgusManager
{
private $auth;
private $config;
public function __construct(Auth $auth, Config $config = null)
{
$this->auth = $auth;
if ($config == null) {
$this->config = new Config();
} else {
$this->config = $config;
}
}
/**
* 视频鉴黄
*
* @param $body body信息
* @param $vid videoID
*
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
* @link https://developer.qiniu.com/dora/manual/4258/video-pulp
*/
public function pulpVideo($body, $vid)
{
$path = '/v1/video/' . $vid;
return $this->arPost($path, $body);
}
private function getArHost()
{
$scheme = "http://";
if ($this->config->useHTTPS == true) {
$scheme = "https://";
}
return $scheme . Config::ARGUS_HOST;
}
private function arPost($path, $body = null)
{
$url = $this->getArHost() . $path;
return $this->post($url, $body);
}
private function post($url, $body)
{
$headers = $this->auth->authorizationV2($url, 'POST', $body, 'application/json');
$headers['Content-Type']='application/json';
$ret = Client::post($url, $body, $headers);
if (!$ret->ok()) {
print($ret->statusCode);
return array(null, new Error($url, $ret));
}
$r = ($ret->body === null) ? array() : $ret->json();
return array($r, null);
}
}
wget 'https://sme10.lists2.roe3.org/kodbox/app/sdks/IO/qiniu/Qiniu/Storage/BucketManager.php'
<?php
namespace Qiniu\Storage;
use Qiniu\Auth;
use Qiniu\Config;
use Qiniu\Zone;
use Qiniu\Http\Client;
use Qiniu\Http\Error;
/**
* 主要涉及了空间资源管理及批量操作接口的实现,具体的接口规格可以参考
*
* @link https://developer.qiniu.com/kodo/api/1274/rs
*/
final class BucketManager
{
private $auth;
private $config;
public function __construct(Auth $auth, Config $config = null)
{
$this->auth = $auth;
if ($config == null) {
$this->config = new Config();
} else {
$this->config = $config;
}
}
/**
* 获取指定账号下所有的空间名。
*
* @return string[] 包含所有空间名
*/
public function buckets($shared = true)
{
$includeShared = "false";
if ($shared === true) {
$includeShared = "true";
}
return $this->rsGet('/buckets?shared=' . $includeShared);
}
/**
* 获取指定空间绑定的所有的域名
*
* @return string[] 包含所有空间域名
*/
public function domains($bucket)
{
return $this->apiGet('/v6/domain/list?tbl=' . $bucket);
}
/**
* 获取空间绑定的域名列表
* @return string[] 包含空间绑定的所有域名
*/
/**
* 列取空间的文件列表
*
* @param $bucket 空间名
* @param $prefix 列举前缀
* @param $marker 列举标识符
* @param $limit 单次列举个数限制
* @param $delimiter 指定目录分隔符
*
* @return array 包含文件信息的数组,类似:[
* {
* "hash" => "<Hash string>",
* "key" => "<Key string>",
* "fsize" => "<file size>",
* "putTime" => "<file modify time>"
* },
* ...
* ]
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/list.html
*/
public function listFiles($bucket, $prefix = null, $marker = null, $limit = 1000, $delimiter = null)
{
$query = array('bucket' => $bucket);
\Qiniu\setWithoutEmpty($query, 'prefix', $prefix);
\Qiniu\setWithoutEmpty($query, 'marker', $marker);
\Qiniu\setWithoutEmpty($query, 'limit', $limit);
\Qiniu\setWithoutEmpty($query, 'delimiter', $delimiter);
$url = $this->getRsfHost() . '/list?' . http_build_query($query);
return $this->get($url);
}
/**
* 获取资源的元信息,但不返回文件内容
*
* @param $bucket 待获取信息资源所在的空间
* @param $key 待获取资源的文件名
*
* @return array 包含文件信息的数组,类似:
* [
* "hash" => "<Hash string>",
* "key" => "<Key string>",
* "fsize" => <file size>,
* "putTime" => "<file modify time>"
* "fileType" => <file type>
* ]
*
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/stat.html
*/
public function stat($bucket, $key)
{
$path = '/stat/' . \Qiniu\entry($bucket, $key);
return $this->rsGet($path);
}
/**
* 删除指定资源
*
* @param $bucket 待删除资源所在的空间
* @param $key 待删除资源的文件名
*
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/delete.html
*/
public function delete($bucket, $key)
{
$path = '/delete/' . \Qiniu\entry($bucket, $key);
list(, $error) = $this->rsPost($path);
return $error;
}
/**
* 给资源进行重命名,本质为move操作。
*
* @param $bucket 待操作资源所在空间
* @param $oldname 待操作资源文件名
* @param $newname 目标资源文件名
*
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
*/
public function rename($bucket, $oldname, $newname)
{
return $this->move($bucket, $oldname, $bucket, $newname);
}
/**
* 给资源进行重命名,本质为move操作。
*
* @param $from_bucket 待操作资源所在空间
* @param $from_key 待操作资源文件名
* @param $to_bucket 目标资源空间名
* @param $to_key 目标资源文件名
*
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/copy.html
*/
public function copy($from_bucket, $from_key, $to_bucket, $to_key, $force = false)
{
$from = \Qiniu\entry($from_bucket, $from_key);
$to = \Qiniu\entry($to_bucket, $to_key);
$path = '/copy/' . $from . '/' . $to;
if ($force === true) {
$path .= '/force/true';
}
list(, $error) = $this->rsPost($path);
return $error;
}
/**
* 将资源从一个空间到另一个空间
*
* @param $from_bucket 待操作资源所在空间
* @param $from_key 待操作资源文件名
* @param $to_bucket 目标资源空间名
* @param $to_key 目标资源文件名
*
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/move.html
*/
public function move($from_bucket, $from_key, $to_bucket, $to_key, $force = false)
{
$from = \Qiniu\entry($from_bucket, $from_key);
$to = \Qiniu\entry($to_bucket, $to_key);
$path = '/move/' . $from . '/' . $to;
if ($force) {
$path .= '/force/true';
}
list(, $error) = $this->rsPost($path);
return $error;
}
/**
* 主动修改指定资源的文件类型
*
* @param $bucket 待操作资源所在空间
* @param $key 待操作资源文件名
* @param $mime 待操作文件目标mimeType
*
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/chgm.html
*/
public function changeMime($bucket, $key, $mime)
{
$resource = \Qiniu\entry($bucket, $key);
$encode_mime = \Qiniu\base64_urlSafeEncode($mime);
$path = '/chgm/' . $resource . '/mime/' . $encode_mime;
list(, $error) = $this->rsPost($path);
return $error;
}
/**
* 修改指定资源的存储类型
*
* @param $bucket 待操作资源所在空间
* @param $key 待操作资源文件名
* @param $fileType 待操作文件目标文件类型
*
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
* @link https://developer.qiniu.com/kodo/api/3710/modify-the-file-type
*/
public function changeType($bucket, $key, $fileType)
{
$resource = \Qiniu\entry($bucket, $key);
$path = '/chtype/' . $resource . '/type/' . $fileType;
list(, $error) = $this->rsPost($path);
return $error;
}
/**
* 修改文件的存储状态,即禁用状态和启用状态间的的互相转换
*
* @param $bucket 待操作资源所在空间
* @param $key 待操作资源文件名
* @param $status 待操作文件目标文件类型
*
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
* @link https://developer.qiniu.com/kodo/api/4173/modify-the-file-status
*/
public function changeStatus($bucket, $key, $status)
{
$resource = \Qiniu\entry($bucket, $key);
$path = '/chstatus/' . $resource . '/status/' . $status;
list(, $error) = $this->rsPost($path);
return $error;
}
/**
* 从指定URL抓取资源,并将该资源存储到指定空间中
*
* @param $url 指定的URL
* @param $bucket 目标资源空间
* @param $key 目标资源文件名
*
* @return array 包含已拉取的文件信息。
* 成功时: [
* [
* "hash" => "<Hash string>",
* "key" => "<Key string>"
* ],
* null
* ]
*
* 失败时: [
* null,
* Qiniu/Http/Error
* ]
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html
*/
public function fetch($url, $bucket, $key = null)
{
$resource = \Qiniu\base64_urlSafeEncode($url);
$to = \Qiniu\entry($bucket, $key);
$path = '/fetch/' . $resource . '/to/' . $to;
$ak = $this->auth->getAccessKey();
$ioHost = $this->config->getIovipHost($ak, $bucket);
$url = $ioHost . $path;
return $this->post($url, null);
}
/**
* 从镜像源站抓取资源到空间中,如果空间中已经存在,则覆盖该资源
*
* @param $bucket 待获取资源所在的空间
* @param $key 代获取资源文件名
*
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/prefetch.html
*/
public function prefetch($bucket, $key)
{
$resource = \Qiniu\entry($bucket, $key);
$path = '/prefetch/' . $resource;
$ak = $this->auth->getAccessKey();
$ioHost = $this->config->getIovipHost($ak, $bucket);
$url = $ioHost . $path;
list(, $error) = $this->post($url, null);
return $error;
}
/**
* 在单次请求中进行多个资源管理操作
*
* @param $operations 资源管理操作数组
*
* @return array 每个资源的处理情况,结果类似:
* [
* { "code" => <HttpCode int>, "data" => <Data> },
* { "code" => <HttpCode int> },
* { "code" => <HttpCode int> },
* { "code" => <HttpCode int> },
* { "code" => <HttpCode int>, "data" => { "error": "<ErrorMessage string>" } },
* ...
* ]
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/batch.html
*/
public function batch($operations)
{
$params = 'op=' . implode('&op=', $operations);
return $this->rsPost('/batch', $params);
}
/**
* 设置文件的生命周期
*
* @param $bucket 设置文件生命周期文件所在的空间
* @param $key 设置文件生命周期文件的文件名
* @param $days 设置该文件多少天后删除,当$days设置为0时表示取消该文件的生命周期
*
* @return Mixed
* @link https://developer.qiniu.com/kodo/api/update-file-lifecycle
*/
public function deleteAfterDays($bucket, $key, $days)
{
$entry = \Qiniu\entry($bucket, $key);
$path = "/deleteAfterDays/$entry/$days";
list(, $error) = $this->rsPost($path);
return $error;
}
private function getRsfHost()
{
$scheme = "http://";
if ($this->config->useHTTPS == true) {
$scheme = "https://";
}
return $scheme . Config::RSF_HOST;
}
private function getRsHost()
{
$scheme = "http://";
if ($this->config->useHTTPS == true) {
$scheme = "https://";
}
return $scheme . Config::RS_HOST;
}
private function getApiHost()
{
$scheme = "http://";
if ($this->config->useHTTPS == true) {
$scheme = "https://";
}
return $scheme . Config::API_HOST;
}
private function rsPost($path, $body = null)
{
$url = $this->getRsHost() . $path;
return $this->post($url, $body);
}
private function apiGet($path)
{
$url = $this->getApiHost() . $path;
return $this->get($url);
}
private function rsGet($path)
{
$url = $this->getRsHost() . $path;
return $this->get($url);
}
private function get($url)
{
$headers = $this->auth->authorization($url);
$ret = Client::get($url, $headers);
if (!$ret->ok()) {
return array(null, new Error($url, $ret));
}
return array($ret->json(), null);
}
private function post($url, $body)
{
$headers = $this->auth->authorization($url, $body, 'application/x-www-form-urlencoded');
$ret = Client::post($url, $body, $headers);
if (!$ret->ok()) {
return array(null, new Error($url, $ret));
}
$r = ($ret->body === null) ? array() : $ret->json();
return array($r, null);
}
public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket, $force)
{
return self::twoKeyBatch('/copy', $source_bucket, $key_pairs, $target_bucket, $force);
}
public static function buildBatchRename($bucket, $key_pairs, $force)
{
return self::buildBatchMove($bucket, $key_pairs, $bucket, $force);
}
public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket, $force)
{
return self::twoKeyBatch('/move', $source_bucket, $key_pairs, $target_bucket, $force);
}
public static function buildBatchDelete($bucket, $keys)
{
return self::oneKeyBatch('/delete', $bucket, $keys);
}
public static function buildBatchStat($bucket, $keys)
{
return self::oneKeyBatch('/stat', $bucket, $keys);
}
public static function buildBatchDeleteAfterDays($bucket, $key_day_pairs)
{
$data = array();
foreach ($key_day_pairs as $key => $day) {
array_push($data, '/deleteAfterDays/' . \Qiniu\entry($bucket, $key) . '/' . $day);
}
return $data;
}
public static function buildBatchChangeMime($bucket, $key_mime_pairs)
{
$data = array();
foreach ($key_mime_pairs as $key => $mime) {
array_push($data, '/chgm/' . \Qiniu\entry($bucket, $key) . '/mime/' . base64_encode($mime));
}
return $data;
}
public static function buildBatchChangeType($bucket, $key_type_pairs)
{
$data = array();
foreach ($key_type_pairs as $key => $type) {
array_push($data, '/chtype/' . \Qiniu\entry($bucket, $key) . '/type/' . $type);
}
return $data;
}
private static function oneKeyBatch($operation, $bucket, $keys)
{
$data = array();
foreach ($keys as $key) {
array_push($data, $operation . '/' . \Qiniu\entry($bucket, $key));
}
return $data;
}
private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket, $force)
{
if ($target_bucket === null) {
$target_bucket = $source_bucket;
}
$data = array();
$forceOp = "false";
if ($force) {
$forceOp = "true";
}
foreach ($key_pairs as $from_key => $to_key) {
$from = \Qiniu\entry($source_bucket, $from_key);
$to = \Qiniu\entry($target_bucket, $to_key);
array_push($data, $operation . '/' . $from . '/' . $to . "/force/" . $forceOp);
}
return $data;
}
}
wget 'https://sme10.lists2.roe3.org/kodbox/app/sdks/IO/qiniu/Qiniu/Storage/FormUploader.php'
<?php
namespace Qiniu\Storage;
use Qiniu\Http\Client;
use Qiniu\Http\Error;
final class FormUploader
{
/**
* 上传二进制流到七牛, 内部使用
*
* @param $upToken 上传凭证
* @param $key 上传文件名
* @param $data 上传二进制流
* @param $config 上传配置
* @param $params 自定义变量,规格参考
* http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar
* @param $mime 上传数据的mimeType
*
* @return array 包含已上传文件的信息,类似:
* [
* "hash" => "<Hash string>",
* "key" => "<Key string>"
* ]
*/
public static function put(
$upToken,
$key,
$data,
$config,
$params,
$mime,
$fname
) {
$fields = array('token' => $upToken);
if ($key === null) {
$fname='nullkey';
} else {
$fields['key'] = $key;
}
//enable crc32 check by default
$fields['crc32'] = \Qiniu\crc32_data($data);
if ($params) {
foreach ($params as $k => $v) {
$fields[$k] = $v;
}
}
list($accessKey, $bucket, $err) = \Qiniu\explodeUpToken($upToken);
if ($err != null) {
return array(null, $err);
}
$upHost = $config->getUpHost($accessKey, $bucket);
$response = Client::multipartPost($upHost, $fields, 'file', $fname, $data, $mime);
if (!$response->ok()) {
return array(null, new Error($upHost, $response));
}
return array($response->json(), null);
}
/**
* 上传文件到七牛,内部使用
*
* @param $upToken 上传凭证
* @param $key 上传文件名
* @param $filePath 上传文件的路径
* @param $config 上传配置
* @param $params 自定义变量,规格参考
* http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar
* @param $mime 上传数据的mimeType
*
* @return array 包含已上传文件的信息,类似:
* [
* "hash" => "<Hash string>",
* "key" => "<Key string>"
* ]
*/
public static function putFile(
$upToken,
$key,
$filePath,
$config,
$params,
$mime
) {
$fields = array('token' => $upToken, 'file' => self::createFile($filePath, $mime));
if ($key !== null) {
$fields['key'] = $key;
}
$fields['crc32'] = \Qiniu\crc32_file($filePath);
if ($params) {
foreach ($params as $k => $v) {
$fields[$k] = $v;
}
}
$fields['key'] = $key;
$headers = array('Content-Type' => 'multipart/form-data');
list($accessKey, $bucket, $err) = \Qiniu\explodeUpToken($upToken);
if ($err != null) {
return array(null, $err);
}
$upHost = $config->getUpHost($accessKey, $bucket);
$response = Client::post($upHost, $fields, $headers);
if (!$response->ok()) {
return array(null, new Error($upHost, $response));
}
return array($response->json(), null);
}
private static function createFile($filename, $mime)
{
// PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
// See: https://wiki.php.net/rfc/curl-file-upload
if (function_exists('curl_file_create')) {
return curl_file_create($filename, $mime);
}
// Use the old style if using an older version of PHP
$value = "@{$filename}";
if (!empty($mime)) {
$value .= ';type=' . $mime;
}
return $value;
}
}
wget 'https://sme10.lists2.roe3.org/kodbox/app/sdks/IO/qiniu/Qiniu/Storage/ResumeUploader.php'
<?php
namespace Qiniu\Storage;
use Qiniu\Config;
use Qiniu\Http\Client;
use Qiniu\Http\Error;
/**
* 断点续上传类, 该类主要实现了断点续上传中的分块上传,
* 以及相应地创建块和创建文件过程.
*
* @link http://developer.qiniu.com/docs/v6/api/reference/up/mkblk.html
* @link http://developer.qiniu.com/docs/v6/api/reference/up/mkfile.html
*/
final class ResumeUploader
{
private $upToken;
private $key;
private $inputStream;
private $size;
private $params;
private $mime;
private $contexts;
private $host;
private $currentUrl;
private $config;
/**
* 上传二进制流到七牛
*
* @param $upToken 上传凭证
* @param $key 上传文件名
* @param $inputStream 上传二进制流
* @param $size 上传流的大小
* @param $params 自定义变量
* @param $mime 上传数据的mimeType
*
* @link http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar
*/
public function __construct(
$upToken,
$key,
$inputStream,
$size,
$params,
$mime,
$config
) {
$this->upToken = $upToken;
$this->key = $key;
$this->inputStream = $inputStream;
$this->size = $size;
$this->params = $params;
$this->mime = $mime;
$this->contexts = array();
$this->config = $config;
list($accessKey, $bucket, $err) = \Qiniu\explodeUpToken($upToken);
if ($err != null) {
return array(null, $err);
}
$upHost = $config->getUpHost($accessKey, $bucket);
if ($err != null) {
throw new \Exception($err->message(), 1);
}
$this->host = $upHost;
}
/**
* 上传操作
*/
public function upload($fname)
{
$uploaded = 0;
while ($uploaded < $this->size) {
$blockSize = $this->blockSize($uploaded);
$data = fread($this->inputStream, $blockSize);
if ($data === false) {
throw new \Exception("file read failed", 1);
}
$crc = \Qiniu\crc32_data($data);
$response = $this->makeBlock($data, $blockSize);
$ret = null;
if ($response->ok() && $response->json() != null) {
$ret = $response->json();
}
if ($response->statusCode < 0) {
list($accessKey, $bucket, $err) = \Qiniu\explodeUpToken($this->upToken);
if ($err != null) {
return array(null, $err);
}
$upHostBackup = $this->config->getUpBackupHost($accessKey, $bucket);
$this->host = $upHostBackup;
}
if ($response->needRetry() || !isset($ret['crc32']) || $crc != $ret['crc32']) {
$response = $this->makeBlock($data, $blockSize);
$ret = $response->json();
}
if (!$response->ok() || !isset($ret['crc32']) || $crc != $ret['crc32']) {
return array(null, new Error($this->currentUrl, $response));
}
array_push($this->contexts, $ret['ctx']);
$uploaded += $blockSize;
}
return $this->makeFile($fname);
}
/**
* 创建块
*/
private function makeBlock($block, $blockSize)
{
$url = $this->host . '/mkblk/' . $blockSize;
return $this->post($url, $block);
}
private function fileUrl($fname)
{
$url = $this->host . '/mkfile/' . $this->size;
$url .= '/mimeType/' . \Qiniu\base64_urlSafeEncode($this->mime);
if ($this->key != null) {
$url .= '/key/' . \Qiniu\base64_urlSafeEncode($this->key);
}
$url .= '/fname/' . \Qiniu\base64_urlSafeEncode($fname);
if (!empty($this->params)) {
foreach ($this->params as $key => $value) {
$val = \Qiniu\base64_urlSafeEncode($value);
$url .= "/$key/$val";
}
}
return $url;
}
/**
* 创建文件
*/
private function makeFile($fname)
{
$url = $this->fileUrl($fname);
$body = implode(',', $this->contexts);
$response = $this->post($url, $body);
if ($response->needRetry()) {
$response = $this->post($url, $body);
}
if (!$response->ok()) {
return array(null, new Error($this->currentUrl, $response));
}
return array($response->json(), null);
}
private function post($url, $data)
{
$this->currentUrl = $url;
$headers = array('Authorization' => 'UpToken ' . $this->upToken);
return Client::post($url, $data, $headers);
}
private function blockSize($uploaded)
{
if ($this->size < $uploaded + Config::BLOCK_SIZE) {
return $this->size - $uploaded;
}
return Config::BLOCK_SIZE;
}
}
wget 'https://sme10.lists2.roe3.org/kodbox/app/sdks/IO/qiniu/Qiniu/Storage/UploadManager.php'
<?php
namespace Qiniu\Storage;
use Qiniu\Config;
use Qiniu\Http\HttpClient;
use Qiniu\Storage\ResumeUploader;
use Qiniu\Storage\FormUploader;
/**
* 主要涉及了资源上传接口的实现
*
* @link http://developer.qiniu.com/docs/v6/api/reference/up/
*/
final class UploadManager
{
private $config;
public function __construct(Config $config = null)
{
if ($config === null) {
$config = new Config();
}
$this->config = $config;
}
/**
* 上传二进制流到七牛
*
* @param $upToken 上传凭证
* @param $key 上传文件名
* @param $data 上传二进制流
* @param $params 自定义变量,规格参考
* http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar
* @param $mime 上传数据的mimeType
* @param $checkCrc 是否校验crc32
*
* @return array 包含已上传文件的信息,类似:
* [
* "hash" => "<Hash string>",
* "key" => "<Key string>"
* ]
*/
public function put(
$upToken,
$key,
$data,
$params = null,
$mime = 'application/octet-stream',
$fname = null
) {
$params = self::trimParams($params);
return FormUploader::put(
$upToken,
$key,
$data,
$this->config,
$params,
$mime,
$fname
);
}
/**
* 上传文件到七牛
*
* @param $upToken 上传凭证
* @param $key 上传文件名
* @param $filePath 上传文件的路径
* @param $params 自定义变量,规格参考
* http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar
* @param $mime 上传数据的mimeType
* @param $checkCrc 是否校验crc32
*
* @return array 包含已上传文件的信息,类似:
* [
* "hash" => "<Hash string>",
* "key" => "<Key string>"
* ]
*/
public function putFile(
$upToken,
$key,
$filePath,
$params = null,
$mime = 'application/octet-stream',
$checkCrc = false
) {
$file = fopen($filePath, 'rb');
if ($file === false) {
throw new \Exception("file can not open", 1);
}
$params = self::trimParams($params);
$stat = fstat($file);
$size = $stat['size'] ? $stat['size'] : 1024; // 空文件(0)则fread报错
if ($size <= Config::BLOCK_SIZE) {
$data = fread($file, $size);
fclose($file);
if ($data === false) {
throw new \Exception("file can not read", 1);
}
return FormUploader::put(
$upToken,
$key,
$data,
$this->config,
$params,
$mime,
basename($filePath)
);
}
$up = new ResumeUploader(
$upToken,
$key,
$file,
$size,
$params,
$mime,
$this->config
);
$ret = $up->upload(basename($filePath));
fclose($file);
return $ret;
}
public static function trimParams($params)
{
if ($params === null) {
return null;
}
$ret = array();
foreach ($params as $k => $v) {
$pos1 = strpos($k, 'x:');
$pos2 = strpos($k, 'x-qn-meta-');
if (($pos1 === 0 || $pos2 === 0) && !empty($v)) {
$ret[$k] = $v;
}
}
return $ret;
}
}