file_get_contents read the file element
str_replace ( 'the old ID', "a new replacement identity", 'all elements')
Save the file file_put_contents elements
We template page read by the controller, the default identity {% ios_url%} {% android_url%} alternate route
Controller
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'));
}
Template page
<div class="download">
<br/>
<br/>
<br/>
<div class="iosBox">
<p style="color: #000a39;font-size: 12px;width: 250px;margin: 0 auto;text-align: left;">
安装完成后需要设置信任,手动设置步骤
【设置】 -> 【通用】-> 【描述文件与设备管理】
</p>
<a href="{%ios_url%}" id="phoneIos" class="IsPhone ios">
<p class="ios" onclick="iosClick()">
<span>苹果版下载</span>
</p>
<!--<p><img src="img/ios-qrcode.png?t=0.75272" alt="" class="qrcode" /></p>-->
</a>
</div>
<div class="androidBox">
<p style="color: #000a39;font-size: 12px;width: 250px;margin: 0 auto;text-align: left;">
<br>
<br>
</p>
<a href="{%android_url%}" id="phoneAndroid" class="IsPhone android">
<p class="Android">
<span>安卓版下载</span>
</p>
<!--<p><img src="img/android-qrcode.png?t=0.75272" alt="" class="qrcode"/></p>-->
</a>
</div>
</div>
Static pages
<div class="download">
<br/>
<br/>
<br/>
<div class="iosBox">
<p style="color: #000a39;font-size: 12px;width: 250px;margin: 0 auto;text-align: left;">
安装完成后需要设置信任,手动设置步骤
【设置】 -> 【通用】-> 【描述文件与设备管理】
</p>
<a href="https://####/cn/app/%E9%93%BE%E7%B3%BB/id1489448519" id="phoneIos" class="IsPhone ios">
<p class="ios" onclick="iosClick()">
<span>苹果版下载</span>
</p>
<!--<p><img src="img/ios-qrcode.png?t=0.75272" alt="" class="qrcode" /></p>-->
</a>
</div>
<div class="androidBox">
<p style="color: #000a39;font-size: 12px;width: 250px;margin: 0 auto;text-align: left;">
<br>
<br>
</p>
<a href="https://####/client/share/download/Android-2019-10-24/ChainChat.apk" id="phoneAndroid" class="IsPhone android">
<p class="Android">
<span>安卓版下载</span>
</p>
<!--<p><img src="img/android-qrcode.png?t=0.75272" alt="" class="qrcode"/></p>-->
</a>
</div>
</div>