コード例 #1
0
 /**
  * 上传至阿里云视频或音频
  * @return array
  */
 public function multiupload($weiba_id, $post_id, $uploadFile, $upImage = null)
 {
     //$this->mid = $this->mid;
     //$this->error($this->mid);
     //判断是否是圈主
     $weibaer = D('weiba')->where(array('uid' => $this->mid))->field('weiba_id')->select();
     $manage = D('user_group_link')->where(array('uid' => $this->mid))->field('user_group_id')->find();
     if ($weibaer == null || $manage['user_group_id'] != 1) {
         return array('status' => 0, 'message' => '您还没有权限发表视频或音频,仅限管理员或圈主发表!');
     } else {
         //$uploadFile = 'E:\007.JPG';
         tsload('./addons/oss/samples/RunAll.php');
         //判定是否是文件夹
         if (is_dir($uploadFile)) {
             return array('status' => '0', 'message' => '不支持文件夹上传');
             //                $arr = uploadDir($uploadFile);
             //                $data['up_oss_type'] = 2;
             //print_r($arr);
             //                $info = pathinfo($uploadFile);
             //                echo $info['extension'];
         } else {
             // echo $uploadFile.'<br/>';var_dump(filesize($uploadFile));exit();
             if ($upImage != null) {
                 if (file_exists($upImage)) {
                     //var_dump($upImage);
                     $info = pathinfo($upImage);
                     $extension = strtolower($info['extension']);
                     //分片上传
                     $arr = putObjectByRawApis($upImage, $extension);
                     if ($arr != null) {
                         $objectMeta = getObjectMeta($arr['object']);
                         $image_path = $objectMeta['oss-request-url'];
                         $upImage = str_replace('http://ts-video.oss-cn-hangzhou.aliyuncs.com', 'http://video.chuangyejia.com', $image_path);
                     }
                 } else {
                     return array('status' => '0', 'message' => '上传失败');
                 }
             }
             $info = pathinfo($uploadFile);
             $extension = $info['extension'];
             $data['up_oss_type'] = 1;
             //分片上传
             $arr = putObjectByRawApis($uploadFile, $extension);
             //print_r($arr);
         }
         //$this->error($arr['object']);
         if ($arr != null) {
             //得到上传文件的oss属性
             $objectMeta = getObjectMeta($arr['object']);
             // $this->error( '测试');
             //                print_r($objectMeta);
             //得到文件路径
             $object_path = $objectMeta['oss-request-url'];
             //echo $object_path;
             $object_size = $objectMeta['content-length'];
             $info = pathinfo($object_path);
             $object_path_extension = $info['extension'];
             $data['up_oss_extension'] = $object_path_extension;
             $data['uid'] = $this->mid;
             $data['weiba_id'] = $weiba_id;
             $data['post_id'] = $post_id;
             $data['up_oss_image'] = $upImage;
             //                $data['up_oss_title'] = $title;
             //                $data['up_oss_describe'] = $Describe;
             $data['up_oss_size'] = $object_size;
             $data['up_oss_path'] = str_replace('http://ts-video.oss-cn-hangzhou.aliyuncs.com', 'http://video.chuangyejia.com', $object_path);
             // $data['up_oss_path']=$this->str_replace_once('http://ts-video.oss-cn-hangzhou.aliyuncs.com','http://video.chuangyejia.com',$object_path);
             $data['up_oss_ctime'] = time();
             $flag = M('up_oss')->add($data);
             //print_r($data);
             //                var_dump($flag);
             if ($flag) {
                 return array('status' => '1', 'up_oss_id' => $flag, 'url' => $object_path, 'videoImage' => $upImage, 'message' => '上传成功');
             } else {
                 //return false;
                 return array('status' => '0', 'message' => '上传失败');
                 ///$this->error('上传失败');
             }
         } else {
             return array('status' => '0', 'message' => '上传失败');
             //$this->error('上传失败');
         }
         //  getObject($arr['uploadFile'], $arr['object']);
     }
 }
コード例 #2
0
}
//*******************************简单使用***************************************************************
/**
 * 查看完整用法中的 "putObjectByRawApis"函数,查看使用基础的分片上传api进行文件上传,用户可以基于这个自行实现断点续传等功能
 */
// 使用分片上传接口上传文件, 接口会根据文件大小决定是使用普通上传还是分片上传
$ossClient->multiuploadFile($bucket, "file.php", __FILE__, array());
Common::println("local file " . __FILE__ . " is uploaded to the bucket {$bucket}, file.php");
// 上传本地目录到bucket内的targetdir子目录中
$ossClient->uploadDir($bucket, "targetdir", __DIR__);
Common::println("local dir " . __DIR__ . " is uploaded to the bucket {$bucket}, targetdir/");
// 列出当前未完成的分片上传
$listMultipartUploadInfo = $ossClient->listMultipartUploads($bucket, array());
//******************************* 完整用法参考下面函数 ****************************************************
multiuploadFile($ossClient, $bucket);
putObjectByRawApis($ossClient, $bucket);
uploadDir($ossClient, $bucket);
listMultipartUploads($ossClient, $bucket);
/**
 * 通过multipart上传文件
 *
 * @param OssClient $ossClient OssClient实例
 * @param string $bucket 存储空间名称
 * @return null
 */
function multiuploadFile($ossClient, $bucket)
{
    $object = "test/multipart-test.txt";
    $file = __FILE__;
    $options = array();
    try {
コード例 #3
0
 /**
  * 上传至阿里云视频或音频
  * @return array
  */
 public function multiupload($weiba_id, $post_id, $uploadFile, $upImage = null)
 {
     $this->user_id = empty($this->user_id) ? $this->mid : $this->user_id;
     $this->user_id = 73;
     //        $weiba_id = $_REQUEST['weiba_id'];
     //        $post_id = $_REQUEST['post_id'];
     //        $title = $_REQUEST['uploadTitle'];
     //        $uploadFile = $_REQUEST['uploadFile'];
     //        $Describe = $_REQUEST['Describe'];
     //判断是否是圈主
     $weibaer = D('weiba')->where(array('uid' => $this->user_id))->field('weiba_id')->select();
     $manage = D('user_group_link')->where(array('uid' => $this->user_id))->field('user_group_id')->find();
     if ($weibaer == null || $manage['user_group_id'] != 1) {
         return array('status' => 0, 'message' => '您还没有权限发表视频或音频,仅限管理员或圈主发表!');
     } else {
         //$uploadFile = 'E:\007.JPG';
         tsload('./addons/oss/samples/RunAll.php');
         //判定是否是文件夹
         if (is_dir($uploadFile)) {
             return false;
             //                $arr = uploadDir($uploadFile);
             //                $data['up_oss_type'] = 2;
             //print_r($arr);
             //                $info = pathinfo($uploadFile);
             //                echo $info['extension'];
         } else {
             $info = pathinfo($uploadFile);
             $extension = $info['extension'];
             $data['up_oss_type'] = 1;
             //分片上传
             $arr = putObjectByRawApis($uploadFile, $extension);
             //print_r($arr);
         }
         if ($arr != null) {
             //得到oss上文件的属性
             $objectMeta = getObjectMeta($arr['object']);
             //print_r($objectMeta);
             //得到文件路径
             $object_path = $objectMeta['oss-request-url'];
             //echo $object_path;
             $object_size = $objectMeta['_info']['header_size'];
             $info = pathinfo($object_path);
             $object_path_extension = $info['extension'];
             //                uid int(9) not null comment '用户id',
             //                weiba_id int(9) not null comment '微吧id',
             //                post_id int(9) not null comment '帖子id',
             //                up_oss_image varchar(255) default null comment '视频图片',
             //                up_oss_title VARCHAR(255)default null comment '标题',
             //                up_oss_describe text default null comment '介绍',
             //                up_oss_type varchar(255) default null comment '上传类型:1:文件,2:文件夹',
             //                up_oss_extension varchar(255) default null comment '上传文件后缀',
             //                up_oss_path varchar(255)not null comment '路径',
             //                up_oss_size varchar(255)comment '上传大小',
             //                up_oss_ctime int(9) default null comment '上传时间'
             //
             $data['up_oss_extension'] = $object_path_extension;
             $data['uid'] = $this->user_id;
             $data['weiba_id'] = $weiba_id;
             $data['post_id'] = $post_id;
             $data['up_oss_image'] = $upImage;
             //                $data['up_oss_title'] = $title;
             //                $data['up_oss_describe'] = $Describe;
             $data['up_oss_size'] = $object_size;
             $data['up_oss_path'] = $object_path;
             $data['up_oss_ctime'] = time();
             $flag = M('up_oss')->add($data);
             print_r($data);
             var_dump($flag);
             if ($flag) {
                 return true;
                 /*return array(
                                         'status' => '1',
                 //                        'videoUrl' => $object_path,
                 //                        'musicUrl' => '',
                                         'message' => '上传成功'
                                     );*/
             } else {
                 return false;
                 /*return array(
                       'status' => '0',
                       'message' => '上传失败'
                   );*/
             }
             /*if (strtolower($object_path_extension) == 'mp4') {
                   return array(
                       'status' => '1',
                       'videoUrl' => $object_path,
                       'musicUrl' => '',
                       'message' => '上传成功'
                   );
               } else if (strtolower($object_path_extension) == 'mp3') {
                   return array(
                       'status' => '1',
                       'videoUrl' => '',
                       'musicUrl' => $object_path,
                       'message' => '上传成功'
                   );
               } else if (strtolower($object_path_extension) == null) {
                   return array(
                       'status' => '1',
                       'videoUrl' => '',
                       'musicUrl' => '',
                       'dirUrl' =>$object_path,
                       'message' => '上传成功'
                   );
               }*/
         } else {
             return array('status' => '0', 'videoUrl' => '', 'musicUrl' => '', 'message' => '上传失败');
         }
         //  getObject($arr['uploadFile'], $arr['object']);
     }
 }