用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
~~~ <?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; } } ~~~