替换静态页面 file_get_contents str_replace file_put_contents修改通过模板页面修改静态页面的标签

file_get_contents 读取文件元素

str_replace('旧的标识',"新的替换标识",'所有元素') 

file_put_contents 保存文件元素

我们通过控制器读取模板页面,通过默认标识{%ios_url%} {%android_url%}替换路径

控制器

public function downloadUrl(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'ios_url' => 'required|string',
            'android_url' => 'required|string',
        ]);
        if ($validator->fails()) {
            return response_json(402, $validator->errors()->first());
        }
        $ios_url = $request->input('ios_url');
        $android_url = $request->input('android_url');
        //获取库中存的路径
        $info = AppVersion::select('download_url')->get()->toArray();
        $oldAndroidUrl = '{%android_url%}';
        $oldIosUrl = '{%ios_url%}';


        $indexHtml = file_get_contents(public_path('self_template/index.html'));
        $indexHtml = str_replace($oldIosUrl, $ios_url, $indexHtml);
        $indexHtml = str_replace($oldAndroidUrl, $android_url, $indexHtml);
        file_put_contents(public_path('web/index.html'), $indexHtml);

        $downloadHtml = file_get_contents(public_path('self_template/download.html'));
        $downloadHtml = str_replace($oldIosUrl, $ios_url, $downloadHtml);
        $downloadHtml = str_replace($oldAndroidUrl, $android_url, $downloadHtml);
        file_put_contents(public_path('client/share/download.html'), $downloadHtml);

        $inviteCnHtml = file_get_contents(public_path('self_template/invite-cn.html'));
        $inviteCnHtml = str_replace($oldIosUrl, $ios_url, $inviteCnHtml);
        $inviteCnHtml = str_replace($oldAndroidUrl, $android_url, $inviteCnHtml);
        file_put_contents(public_path('client/share/invite-cn.html'), $inviteCnHtml);

        AppVersion::where('id', 1)->update(['download_url' => $android_url]);
        AppVersion::where('id', 2)->update(['download_url' => $ios_url]);

        return response_json(200, trans('app.success'));

    }

 

模板页面

  



安装完成后需要设置信任,手动设置步骤 【设置】 -> 【通用】-> 【描述文件与设备管理】

苹果版下载

静态页面

  



安装完成后需要设置信任,手动设置步骤 【设置】 -> 【通用】-> 【描述文件与设备管理】

苹果版下载

 

你可能感兴趣的:(php,前端)