Browse Source

安装包倒序排序取最新包

master
wanghongjun 2 years ago
parent
commit
fc2e4f0d71
  1. 21
      app/common.php
  2. 3
      app/controller/User.php

21
app/common.php

@ -331,4 +331,23 @@ function get_datetime($datetime,$type = 1)
default:
return $datetime;
}
}
}
/**
* 获取最新安装包 已安装包名称倒序排序 取第一个
* @return false|mixed
*/
function get_new_apk_filename():string
{
$public_path = public_path();
$apkDir = $public_path . '/storage/'.'download';
$files = scandir($apkDir); // 获取目标文件夹下的文件名
$files = array_diff($files, ['.', '..']); // 删除
rsort($files); // 以值 倒序排序
return reset($files);
}

3
app/controller/User.php

@ -264,7 +264,8 @@ class User extends BaseController
*/
public function downloadApp()
{
$file_url = get_image_url('download/app-dgg_v1.0.1.apk');//文件路径
$apk_filename = get_new_apk_filename();
$file_url = get_image_url('download/'.$apk_filename);//文件路径
return $this->renderSuccess('成功',['app_url' => $file_url]);
}

Loading…
Cancel
Save