}
file_put_contents($this->filepath.'/'. $this->fileName,$blob);
$this->deleteFileBlob();
}
}
//删除文件块
private function deleteFileBlob(){
for($i=1; $i<= $this->totalBlobNum; $i++){
@unlink($this->filepath.'/'. $this->fileName.'__'.$i);
}
}
//移动文件
private function moveFile(){
$this->touchDir();
$filename = $this->filepath.'/'. $this->fileName.'__'.$this->blobNum;
move_uploaded_file($this->tmpPath,$filename);
}
//API返回数据
public function apiReturn(){
if($this->blobNum == $this->totalBlobNum){
if(file_exists($this->filepath.'/'. $this->fileName)){
$data['code'] = 2;
$data['msg'] = 'success';
$data['file_path'] = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['DOCUMENT_URI']).str_replace('.','',$this->filepath).'/'. $this->fileName;
}
}else{
if(file_exists($this->filepath.'/'. $this->fileName.'__'.$this->blobNum)){
$data['code'] = 1;
$data['msg'] = 'waiting for all';
$data['file_path'] = '';
}
}
header('Content-type: application/json');
echo json_encode($data);
}
//建立上传文件夹
private function touchDir(){
if(!file_exists($this->filepath)){
return mkdir($this->filepath);
}
}
}
//实例化并获取系统变量传参
$upload = new Upload($_FILES['file']['tmp_name'],$_POST['blob_num'],$_POST['total_blob_num'],$_POST['file_name']);
//调用方法,返回结果
$upload->apiReturn();
```
【php大文件切片上传】
推荐阅读
- Aspose-文件转换工具太好用了
- 一点隐私都没有了?聊天记录打码也不安全:大神亲自下场破解
- 轻量、高效、功能强大的微前端框架-MicroApp
- 小庄园的红茶,翠玉茶的功效与作用
- 产后大出血症状
- hr|大学生就业屡屡失败,大企业HR坦言:这些简历不用细看直接淘汰
- 00后|00后的简历有多敢写?表面看着很正经,括号里的字却让HR头大
- 大学|大学毕业生如何提高沟通表达能力?
- 十大品牌牛仔裤清单
- 杨幂|杨幂最新造型太显胖!穿超大码皮衣戴金耳环,翻车亮相还没脖子
