<?php
/**
* 分片上传至oss
* Created by : 谜一样的男子
*/
require_once(dirname(__FILE__).'/aliyun-oss/autoload.php');
use OSS\OssClient;
use OSS\Core\OssException;
class lib_UploadOss
{
protected static $accessKeyId = "yourAccessKeyId";
protected static $accessKeySecret = "yourAccessKeySecret";
# 区域地址如:http://oss-cn-hangzhou.aliyuncs.com
protected static $endpoint = "yourEndpoint";
# Bucket名称,例如examplebucket
protected $bucket= "yourBucketName";
# 上传至oss文件路径 含文件名
protected $object;
# 本地临时文件地址 含临时文件名
protected $filePath;
# 文件后缀
protected $fileExtension;
# 文件名称 不含后缀
protected $fileName;
# oss文件分片上传唯一key
protected $uploadId;
# 本地分片临时文件目录
protected $tempDir = 'uploads_tmp/';
# 上传至oss 文件名
protected $upFileName;
# 上传句柄
protected $ossClient;
# 当前分片索引
protected $chunk;
# 分片总数
protected $chunks;
/**
* lib_UploadOss constructor.
* @param $filePost post信息,包含 分片数量 文件名
* @param $file 分片文件信息
* @param string $dir 自定义oss存放路径
* @throws OssException
*/
public function __construct($filePost,$file,$dir='')
{
if (empty($filePost)) return false;
#前面拼一个字符串,解决中文不能识别bug
$fileInfo = pathinfo(" " . $filePost['name']);
#文件后缀
$this->fileExtension = trim($fileInfo['extension']);
#文件名不含后缀
$this->fileName = trim($fileInfo['filename']);
#文件临时地址
$this->filePath = $file['filedata']['tmp_name'];
#分片索引 oss只支持大于0的分片索引
$this->chunk = $filePost['chunk']+1;
#分片总数
$this->chunks = $filePost['chunks'];
#实例化oss上传类
PHP OSS 分片上传
最新推荐文章于 2025-02-24 10:53:50 发布