GameUpload.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * 游戏上传
  4. */
  5. namespace app\admin\controller;
  6. use Overtrue\Pinyin\Pinyin;
  7. use think\Env;
  8. class GameUpload extends Admin
  9. {
  10. public function index() {
  11. return $this->fetch();
  12. }
  13. /**
  14. * 文件上传
  15. * @param string $value [description]
  16. */
  17. public function UploadBigFile()
  18. {
  19. $pinyin = new Pinyin();
  20. $getParam = input('get.');
  21. $postParam = input('post.');
  22. $name = $pinyin->permalink(substr($postParam['name'],0,strrpos($postParam['name'] ,".")), '');//转中文
  23. $act = $getParam['act'];
  24. $ups = Env::get('MUBAO_PATH').'sygame/'.$name.'/';
  25. $ext_suffix = substr($postParam['name'],strripos($postParam['name'],".")+1);//后缀
  26. $flag = true;
  27. !in_array($ext_suffix, ['ipa','apk']) && $flag = false;//判断后缀名是否符合
  28. if (!$flag) {
  29. $this->error('选择文件错误');
  30. }
  31. if ($act == 'upload') {
  32. $index = $postParam['index'];
  33. $filename = $ups."$index".$name.'.'.$ext_suffix;
  34. if (!file_exists($ups))//如果文件夹不存在
  35. {
  36. mkdir($ups, 0777);
  37. }
  38. //断点上传已经存在的就跳过
  39. if (file_exists($filename)) {
  40. $this->success('上传成功');
  41. }else{
  42. $result = move_uploaded_file($_FILES['data']['tmp_name'], iconv('UTF-8', 'GBK', $filename));
  43. }
  44. if ($result) {
  45. $this->success('上传成功');
  46. } else {
  47. $this->success('上传失败');
  48. }
  49. }
  50. elseif ($_GET['act'] == 'join') {
  51. $total = intval($postParam['total']);
  52. $filename = $ups.$name.'.'.$ext_suffix;
  53. //合并时候判断 存在之前上传过的文件就删除掉在合并
  54. @unlink(iconv('UTF-8', 'GBK', $filename));
  55. for($i = 1; $i<=$total; $i++){
  56. file_put_contents($ups.iconv('UTF-8', 'GBK', $name.'.'.$ext_suffix), file_get_contents(iconv('UTF-8', 'GBK', $ups."$i".$name.'.'.$ext_suffix)), FILE_APPEND);
  57. @unlink(iconv('UTF-8', 'GBK', $ups."$i".$name.'.'.$ext_suffix));
  58. }
  59. $this->success('上传成功');
  60. }
  61. }
  62. }