本文整理匯總了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);
}