hotupdate.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * 客户端热更新相关
  4. * Date: 2017/9/13 0013
  5. * Time: 12:00
  6. */
  7. //请求参数
  8. //print_r($_FILES);
  9. //print_r($_POST);
  10. $subversion = trim($_POST['subversion']);//热更新名称
  11. $actList = $_POST['act']; //act名称
  12. $device = $_POST['device'] == 1 ? 'android' : 'ios'; //设备名称
  13. $stagefile = $_FILES['stagefile']; //上传文件名称名称
  14. //加了_old表示之前的
  15. $act_old = $_POST['act_old'];
  16. $size_old = $_POST['size_old'];
  17. $name_old = $_POST['name_old'];
  18. $code_old = $_POST['code_old'];
  19. $silent_old = $_POST['silent_old'];
  20. $old_stageStrList = '';
  21. if ($act_old) {
  22. foreach ($act_old as $i => $actname) {
  23. $old_stageStrList .= '{size="'.$size_old[$i].'",act="'.$actname.'",name="'.$name_old[$i].'",code="'.$code_old[$i].'",silent="'.$silent_old[$i].'"},';
  24. }
  25. }
  26. if( empty($subversion) ){
  27. return -1;
  28. }
  29. $title = getTitle($subversion);
  30. //循环处理
  31. $stageStrList = '{';
  32. if ($old_stageStrList) {
  33. $stageStrList .= $old_stageStrList;
  34. }
  35. $luaFile = '';//生成的lua文件
  36. $time = time();
  37. $hotuploadPath = '../hotupdatefile/'.$device.'/';
  38. foreach ($stagefile['name'] as $k => $fileName){
  39. if (!$fileName) {
  40. continue;
  41. }
  42. $uploadName = $fileName;
  43. $filePath = $hotuploadPath.$uploadName;
  44. //echo $filePath."<br />";
  45. $tmpName = $stagefile['tmp_name'][$k];
  46. move_uploaded_file($tmpName, $filePath);
  47. $code = md5_file($filePath);
  48. rename($filePath, $hotuploadPath.$code);
  49. $size = round($stagefile['size'][$k]/1024);
  50. $act = trim($actList[$k]);
  51. $silent = 0;
  52. $stageStrList .= '{size="'.$size.'",act="'.$act.'",name="'.$uploadName.'",code="'.$code.'",silent="'.$silent.'"},';
  53. }
  54. $stageStrList = rtrim($stageStrList, ',');
  55. $stageStrList .= '}';
  56. $luaFile = 'local list = {ver = "'.$subversion.'", stage = '.$stageStrList.'} return list';
  57. file_put_contents($hotuploadPath.'flist'.$title, $luaFile);
  58. echo "生成热更新文件成功, 点击查看生成配置文件: <a href='https://crazycoin.superant.vip/hotupdatefile/{$device}/flist{$title}'>flist{$title}</a>";
  59. function getTitle($version){
  60. $arr = explode('.', $version);
  61. array_pop($arr);
  62. $new = implode('.', $arr);
  63. return $new;
  64. }