Ejemplo n.º 1
0
 function do_upload($user_id, $file_name, $source_file)
 {
     $image = new AlibabaImage($this->config['ak'], $this->config['sk'], "TOP");
     $uploadPolicy = new uploadPolicy();
     $uploadPolicy->dir = $user_id;
     //
     $uploadPolicy->name = $file_name;
     // 文件名不/"
     if (!$image->existsFolder($this->namespace, $user_id)) {
         $image->createDir($this->namespace, $user_id);
     }
     $uploadPolicy->namespace = $this->namespace;
     $res = $image->upload($source_file, $uploadPolicy, $opts = array());
     return $res;
 }
Ejemplo n.º 2
0
 public function upload($file)
 {
     global $_G;
     if (!$this->appkey) {
         if (!$_G['setting']['baichuan_name']) {
             $this->msg = '百川上传空间名称未配置';
             return false;
         }
         $this->init($_G['setting']['appkey'], $_G['setting']['secretKey'], 'TOP', $_G['setting']['baichuan_name']);
     }
     $image = new AlibabaImage($this->appkey, $this->accessKey, $this->type);
     $uploadPolicy = new uploadPolicy();
     $uploadPolicy->dir = $this->dir;
     //
     $uploadPolicy->name = $this->name;
     // 文件名不能包含"/"
     $uploadPolicy->namespace = $this->namespace;
     // type =TOP 必填
     $rs = $image->upload($file, $uploadPolicy, $opts = array());
     return $this->check($rs);
 }
Ejemplo n.º 3
0
require_once '../alimage.class.class.php';
$ak = '23165315';
// app key
$sk = '82cef51512dbd85dbf3bfb5768a6b042 ';
// secret key
$image = new AlibabaImage($ak, $sk, "TOP");
$uploadPolicy = new uploadPolicy();
$uploadPolicy->dir = '';
//
$uploadPolicy->name = 'file';
// 文件名不能包含"/"
//$uploadPolicy->namespace= '$bucket'; // type =TOP 必填
$uploadPolicy->bucket = $bucket;
// type =CLOUD 必填
// 小文件上传
$res = $image->upload('image/image.jpg', $uploadPolicy, $opts = array());
var_dump($res);
// 直接使用分片上传接口
$res = $image->uploadSuperfile('image/image.jpg', $uploadPolicy);
var_dump($res);
// 分别调用分片上传接口,对于断点续传场景
$file = 'image/image.jpg';
$fileSize = filesize($file);
$filemd5 = md5_file($file);
$subObjSize = 2345677;
$md5_parts = array();
$res = $image->multipartInit($file, $uploadPolicy, 0, $subObjSize);
var_dump($res);
if ($res['isSuccess']) {
    array_push($md5_parts, array('eTag' => $res['eTag'], 'partNumber' => $res['partNumber']));
    $uploadId = $res['uploadId'];
Ejemplo n.º 4
0
<?php

require_once 'config.php';
require_once 'system/alimage.class.class.php';
function bytesToSize1024($bytes, $precision = 2)
{
    $unit = array('B', 'KB', 'MB');
    return @round($bytes / pow(1024, $i = floor(log($bytes, 1024))), $precision) . ' ' . $unit[$i];
}
$image = new AlibabaImage($ak, $sk, "TOP");
$uploadPolicy = new uploadPolicy();
$uploadPolicy->dir = $ak;
//
$uploadPolicy->name = $_FILES['image_file']['name'];
// ÎļþÃû²»ÄÜ°üº¬"/"
$uploadPolicy->namespace = $bucket;
// type =TOP ±ØÌî
$res = $image->upload($_FILES['image_file']['tmp_name'], $uploadPolicy, $opts = array());
//var_dump($res);
$sFileName = $_FILES['image_file']['name'];
$sFileType = $_FILES['image_file']['type'];
$sFileSize = bytesToSize1024($_FILES['image_file']['size'], 1);
$sFileUrl = $res['url'];
echo <<<EOF
<p>Your file: {$sFileName} has been successfully received.</p>
<p>Type: {$sFileType}</p>
<p>Size: {$sFileSize}</p>
<p>URL:{$sFileUrl}</p>
EOF
;