~~~
<?php
namespace app\tool;
//分片上传测试
class upload
{
private $file_path = '';//上传目录
private $temp_path = '';//php上传临时目录
private $blob_num;//第几片
private $total_num;//总片数
private $file_name;//文件名
private $temp_name;//PHP上传临时目录
public function __construct($filePath, $blobNum, $totalNum, $fileName, $tempName)
{
$this->file_path = $filePath;
$this->blob_num = $blobNum;
$this->total_num = $totalNum;
$this->file_name = $fileName;
$this->temp_name = $tempName;
$this->temp_path = ROOT_PAth . 'public/upload/';
$this->moveFile();
$this->mergeFile();
}
//移动临时文件
private function moveFile()
{
$this->touchDir();
$filename = $this->temp_path . $this->file_name . '_' . $this->blob_num;
move_uploaded_file($this->temp_name, $filename);
}
//合并文件
private function mergeFile()
{
if ($this->blob_num == ($this->total_num - 1)) {
$blob = "";
if (file_exists($this->file_path . iconv('UTF-8', 'GB2312', $this->file_name))) {
@unlink($this->file_path . iconv('UTF-8', 'GB2312', $this->file_name));
}
for ($i = 0; $i < $this->total_num; $i++) {
$blob = file_get_contents($this->temp_path . $this->file_path . "_" . $i);
$last_path = $this->file_path . $this->file_name;
iconv('UTF-8', 'GB2312', $this->file_path . $this->file_name);
file_put_contents($last_path, $blob, FILE_APPEND);
}
$this->deleteTempFile();
}
}
//删除上传的临时文件
private function deleteTempFile()
{
for ($i = 0; $i < $this->total_num; $i++) {
@unlink($this->temp_path . $this->file_name . '_' . $i);
}
}
//创建文件夹
private function touchDir()
{
if (!file_exists($this->file_path)) {
@mkdir($this->file_path, 0777, true);
}
if (!file_exists($this->temp_path)) {
@mkdir($this->temp_path, 0777, true);
}
}
//API返回数据GB
public function apiReturn()
{
if ($this->blob_num == ($this->total_num - 1)) {
//修改文件权限
$oldmask = umask(0);
$res = chmod($this->file_path . $this->file_name, 0777);
umask($oldmask);
$res1 = $this->file_path . $this->file_name;
$res2 = file_exists($res1);
if ($res2) {
$data['code'] = 2;
$data['msg'] = 'success';
$data['file_path'] = $this->file_path . $this->file_name;
}
} else {
if (file_exists($this->temp_path . $this->file_name . '_' . $this->blob_num)) {
$data['code'] = 1;
$data['msg'] = 'waiting for all';
$data['file_path'] = '';
}
}
return $data;
}
}
~~~
- 面试
- php
- laravel
- 安装
- 创建数据
- 创建控制器
- 错误
- 权限认证
- 图形验证码
- 管理员
- 无限分类
- 视频播放
- 推流
- pc页面
- thinkphp5
- 表单提交安全验证
- crontab
- 获取下级所有数据
- 过滤敏感词
- 二维码
- 邀请码
- jwt token
- 笛卡尔
- 高并发解决优化
- 设置多语言
- 计算经纬度两点距离
- 分片上传
- centos swoole
- 查看swoole版本
- centos 安装 redis
- 把整数随机分成n份或者红包
- 生成随机字符串
- 获取上级
- 宝塔搭建nginx推拉流
- 生成二维码海报
- 二维数组去重
- 经纬度 ---边距 和判断是不是范围内
- workerman
- 扩展
- redis
- mysql
- mysql 主从复制
- 定位问题语句
- 列的选择规则
- Enum介绍
- 索引介绍
- 延迟关联
- in 查询陷阱
- limit 优化
- 事务
- 读写分离
- mysql 权限错误
- mysql计算距离
- mysql数据导出导入
- 索引失效
- mysql 语句技巧
- linux
- 配置nginx 高可用
- Nginx内核参数优化
- 配置优化
- nginx-keepalived实现高可用负载
- lvs+keepalived
- centos5关闭防火墙
- nginx操作
- linux操作
- mysql 安装
- php
- 安装phpadmin
- php7安装mongodb
- 查看php位置
- 查找开启的进程端口
- 守护进程
- centos安装php7.2
- centos 错误解决
- 安装php7错误
- mysql 错误
- 支付宝支付
- html
- js 倒计时
- go vscode 配置
- go util
- 获取两个数之间随机数
- java
- lambda
- 随机抽取
- lombok
- springboot
- 常见注解
- 接受参数常用注解
- 文件上传
- 上传错误日志拦截
- 拦截器
- 定时任务
- mybatis
- 关联查询
- 全局配置
- 缓存
- git
- 微信相关
- 体现到零钱
- 服务商转账
- 公众号小程序相关
- 小程序二维码
- svn
- layui