本文整理汇总了PHP中Qiniu_Put函数的典型用法代码示例。如果您正苦于以下问题:PHP Qiniu_Put函数的具体用法?PHP Qiniu_Put怎么用?PHP Qiniu_Put使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Qiniu_Put函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
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'];
}
示例2: saveContent
public function saveContent($token, $filename, $body, $ext = null)
{
list($ret, $err) = Qiniu_Put($token, $filename, $body, $ext);
if (!empty($err)) {
throw new Exception(print_r($err, 1));
}
return $ret;
}
示例3: testPut
public function testPut()
{
$key = 'testPut' . getTid();
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
$upToken = $putPolicy->Token(null);
list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null);
$this->assertNull($err);
$this->assertArrayHasKey('hash', $ret);
var_dump($ret);
list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
$this->assertNull($err);
var_dump($ret);
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$this->assertNull($err);
}
示例4: testPutWithPersistentOps
public function testPutWithPersistentOps()
{
$key = 'testPutWithPersistentOps' . getTid();
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
$putPolicy->PersistentOps = 'avthumb/mp3';
$putPolicy->PersistentNotifyUrl = 'http://someurl/abc';
$upToken = $putPolicy->Token(null);
list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null);
$this->assertNull($err);
$this->assertArrayHasKey('hash', $ret);
$this->assertArrayHasKey('persistentId', $ret);
var_dump($ret);
list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
$this->assertNull($err);
var_dump($ret);
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$this->assertNull($err);
}
示例5: doMobileUpload
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;
}
}
示例6: Qiniu_RS_Put
function Qiniu_RS_Put($self, $bucket, $key, $body, $putExtra)
{
$putPolicy = new Qiniu_RS_PutPolicy("{$bucket}:{$key}");
$upToken = $putPolicy->Token($self->Mac);
return Qiniu_Put($upToken, $key, $body, $putExtra);
}
示例7: imagedestroy
// 上传到服务器
$rsp['msg'] = '请先配置七牛信息 bucket && accessKey && secretKey';
}
if (!$is_gifs) {
imagedestroy($new_image);
}
} else {
// 其它文件
// $rsp['msg'] = '本站暂不支持上传非图片附件';
//
if ($bucket && $accessKey && $secretKey) {
// 上传到七牛
Qiniu_SetKeys($accessKey, $secretKey);
$putPolicy = new Qiniu_RS_PutPolicy($bucket);
$upToken = $putPolicy->Token(null);
list($ret, $err) = Qiniu_Put($upToken, $upload_filename, $_FILES['filetoupload']['tmp_name'], null);
if ($err !== null) {
//var_dump($err);
$rsp['msg'] = '附件保存失败,请稍后再试';
} else {
//var_dump($ret);
$rsp['status'] = 200;
// 返回附件实际地址,有的是 u.qiniudn.com ,请自行修改
$rsp['url'] = '附件:' . $up_name . ' http://' . $bucket . '.qiniudn.com/' . $upload_filename;
$rsp['msg'] = '附件已成功上传';
}
} else {
// 上传到服务器
$rsp['msg'] = '请先配置七牛信息 bucket && accessKey && secretKey';
}
//
示例8: wpjam_qiniutek_put
function wpjam_qiniutek_put($key, $str)
{
global $qiniutek_client;
if (!$qiniutek_client) {
$qiniutek_client = wpjam_get_qiniutek_client();
}
$wpjam_qiniutek = get_option('wpjam-qiniutek');
$qiniutek_bucket = $wpjam_qiniutek['bucket'];
$putPolicy = new Qiniu_RS_PutPolicy($qiniutek_bucket);
$upToken = $putPolicy->Token(null);
if (!function_exists('Qiniu_Put')) {
require_once WP_CONTENT_DIR . "/plugins/wpjam-qiniu/sdk/io.php";
}
list($ret, $err) = Qiniu_Put($upToken, $key, $str, null);
if ($err !== null) {
$msg = ' 发生错误:<span style="color:red">' . $err->Err . '</span><br />';
} else {
$msg = ' 上传成功<br />';
}
return $msg;
}
示例9: getImage
function getImage($url)
{
$file = file_get_contents($url);
return $file;
}
$url = $_POST['url'];
$accessKey = $_POST['accessKey'];
$secretKey = $_POST['secretKey'];
$fileName = $_POST['fileName'];
$bucket = $_POST['bucket'];
if (empty($url) || empty($accessKey) || empty($secretKey) || empty($fileName) || empty($bucket)) {
echo 'error';
} else {
Qiniu_SetKeys($accessKey, $secretKey);
$putPolicy = new Qiniu_RS_PutPolicy($bucket);
$upToken = $putPolicy->Token(null);
$putExtra = new Qiniu_PutExtra();
//dirname(__FILE__) . '/' . getImage($url)
$putExtra->Crc32 = 1;
list($ret, $err) = Qiniu_Put($upToken, $fileName, getImage($url), $putExtra);
$result = array();
if ($err !== null) {
$result['data'] = $err;
$result['status'] = 'fail';
echo json_encode($result);
} else {
$result['data'] = $ret;
$result['status'] = 'success';
echo json_encode($result);
}
}
示例10: CreateFolder
public function CreateFolder($path, $fname)
{
global $_G;
$arr = self::parsePath($path);
$client = self::init($path);
$putPolicy = new Qiniu_RS_PutPolicy($arr['bucket']);
$upToken = $putPolicy->Token(null);
list($ret, $err) = Qiniu_Put($upToken, $arr['object'] . $fname . '/', '', null);
if ($err !== null) {
return array('error' => $err->Code . ':' . $err->Err);
} else {
$ret['isdir'] = true;
}
$icoarr = self::_formatMeta($ret, $arr);
$folderarr = self::getFolderByIcosdata($icoarr);
return array('folderarr' => $folderarr, 'icoarr' => $icoarr);
}
示例11: getRemoteImage
/**
* 远程抓取
* @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);
//.........这里部分代码省略.........
示例12: actionUpmusic
public function actionUpmusic()
{
$songModel = new Song();
if (isset($_POST['Song'])) {
$songModel->attributes = $_POST['Song'];
$songModel->userid = Yii::app()->session['uid'];
if ($songModel->validate()) {
if (!empty($_FILES['songname']['tmp_name'])) {
$file = $_FILES['songname'];
if (!MusicTypeCheck($file['name'], $file['size'])) {
Yii::app()->user->setFlash('upstatus', 'Sorry, 音乐文件大小或格式错误 :(');
$this->redirect(array("Upmusic"));
die;
}
$type = "." . GetFileExtension($file['name']);
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'];
$newname = time() . rand(10000, 99999) . $type;
//先保存记录
$songModel->song = $newname;
if ($songModel->save()) {
/**
*
*/
} else {
Yii::app()->user->setFlash('upstatus', 'Sorry,系统错误,上传音乐失败 :(');
}
Qiniu_SetKeys($accessKey, $secretKey);
$putPolicy = new Qiniu_RS_PutPolicy($bucket);
$upToken = $putPolicy->Token(null);
list($ret, $err) = Qiniu_Put($upToken, $newname, file_get_contents($file['tmp_name']), null);
if ($err === null) {
//成功
/***
*
*/
$this->redirect(array('admin/Imusic'));
} else {
//失败
Yii::app()->user->setFlash('upstatus', 'Sorry,系统错误,上传音乐失败 :(');
}
}
}
}
$data = array('songModel' => $songModel);
$this->render("upmusic", $data);
}
示例13: actionEditblog
public function actionEditblog($id)
{
$label = new Article();
$labels = $label->findAll('userid=:uid', array(':uid' => Yii::app()->session['uid']));
//$labesArray是对应于id,label键值的一维数组
$labesArray[0] = '--请选择--';
foreach ($labels as $l) {
$labesArray[$l->id] = $l->label;
}
$blog = Blog::model();
$blogInfo = $blog->findByPk($id);
$blogInfotmp = $blogInfo;
//存储到session[blogid] 防止imageUP后台处理时有添加一条记录到blog表中
Yii::app()->session['blogid'] = $id;
//七牛上传类
Yii::import('application.vendors.*');
require_once 'Qiniu/io.php';
require_once 'Qiniu/rs.php';
$bucket = Yii::app()->params['bucket'];
$accessKey = Yii::app()->params['accessKey'];
$secretKey = Yii::app()->params['secretKey'];
if (isset($_POST['Blog'])) {
$post = $_POST['Blog'];
//$post['view'] = 0;
$post['time'] = time();
$post['userid'] = Yii::app()->session['uid'];
$blogInfo->attributes = $post;
if ($blogInfo->validate()) {
/**
* 处理图片
* require_once 'UPimage/UPimage.php'; //图片缩略类
* $resizeimage = new resizeimage("1.jpg", "320", "240", "1","2.jpg");
* 1.缩略图
* 2.文章图片 删除就行 添加记录由后台异步处理 //删除文章时处理
*/
//echo CheckUploadFiles($_FILES['thumb']);die;
//1
//a 查出缩略图片并 b删除七牛上的图片 传递一个特殊的字符串
$images = "";
//拼接图片以@方式
if (CheckUploadFiles($_FILES['thumb'])) {
//删除图片
$file = $_FILES['thumb'];
$type = ".jpg";
if (count($file['name']) != 0) {
foreach ($file['name'] as $key => $f) {
if (ImageTypeCheck($file['name'][$key], $file['size'][$key])) {
$newname = time() . rand(10000, 99999) . $type;
Qiniu_SetKeys($accessKey, $secretKey);
$putPolicy = new Qiniu_RS_PutPolicy($bucket);
$upToken = $putPolicy->Token(null);
list($ret, $err) = Qiniu_Put($upToken, $newname, file_get_contents($file['tmp_name'][$key]), null);
if ($err === null) {
//成功
$images .= "http://" . Yii::app()->params['bucket'] . "." . Yii::app()->params['domain'] . "/" . $newname . "@";
} else {
//失败
}
}
}
}
//删除图片
$imgs = GetImageFileName($blogInfotmp->image);
Qiniu_SetKeys($accessKey, $secretKey);
$client = new Qiniu_MacHttpClient(null);
foreach ($imgs as $i) {
if (!isset($client)) {
$client = new Qiniu_MacHttpClient(null);
}
$err = Qiniu_RS_Delete($client, $bucket, $i);
}
} else {
//没有上传图片 不做任何操作 保持原来的图片
$images = $blogInfo->image;
}
//$post['image'] = $images;
$blogInfo->attributes = $post;
//2
//删除文章文字配图 和业务数据库中的记录
// Qiniu_SetKeys($accessKey, $secretKey);
// $client = new Qiniu_MacHttpClient(null);
// $imgageModel = Image::model();
// $textImage = $imgageModel->findAll('blogid=:bid',array('bid'=>$id));
// foreach ($textImage as $ti){
// if(!isset($client))
// $client = new Qiniu_MacHttpClient(null);
//
// $err = Qiniu_RS_Delete($client, $bucket, $ti->image);
// }
// $imgageModel->deleteAll('blogid=:bid',array('bid'=>$id));
$blogInfo->image = $images;
$blogInfo->content = $_POST['content'];
if ($blogInfo->save()) {
/**
* 注销blogid 必须的
*/
Yii::app()->session['blogid'] = null;
Yii::app()->user->setFlash('sendblogsuccess', '修改文章成功 :)');
$this->redirect(array('articles'));
}
//.........这里部分代码省略.........
示例14: put
public function put($content)
{
$key = md5($content);
$upToken = $this->getUpToken();
$i = 0;
do {
list($ret, $err) = Qiniu_Put($upToken, $key, $content, null);
$i++;
/*
* 503 服务端不可用
* 504 服务端操作超时
* 599 服务端操作失败
*/
} while ($i < 3 and $err !== null and in_array($err->Code, array(503, 504, 599)));
if ($err !== null) {
throw new QiniuPutException($err->Err, $err->Code, $key);
} else {
return $ret['key'];
}
}
示例15: testPut_exclusive
public function testPut_exclusive()
{
$key = 'testPut_exclusive' . getTid();
$scope = $this->bucket . ':' . $key;
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$putPolicy = new Qiniu_RS_PutPolicy($scope);
$putPolicy->InsertOnly = 1;
$upToken = $putPolicy->Token(null);
list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null);
$this->assertNull($err);
list($ret, $err) = Qiniu_PutFile($upToken, $key, __FILE__, null);
$this->assertNull($ret);
$this->assertEquals($err->Code, 614);
var_dump($err);
list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
$this->assertNull($err);
$this->assertEquals($ret['mimeType'], 'application/octet-stream');
var_dump($ret);
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$this->assertNull($err);
}