我这里有这个表格:
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>?id={{$theme->id}}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="price" value="{{$theme->price}}">
<input type="hidden" name="id" value="{{$theme->id}}">
<button type="submit" name="SubmitButton" class="btn btn-success"><span class="glyphicon glyphicon-shopping-cart"></span> buy theme</button>
</form>
当我执行此表单(我按"购买主题")时,文件开始下载,但问题是页面本身没有刷新,我不知道如何做到这一点。我希望这个表格像这样工作:我按下按钮 - 主题下载 + 页面刷新或重定向到主页。有可能以某种方式吗?谢谢。
顺便说一句,我正在使用拉拉维尔 5
编辑
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename='"".str_replace(" ", "_", $arr['file'])."'"");
header('Location: index.php');
我添加了header('Location: index.php');它会重定向到主页,但下载不会开始。
路线:
Route::get('/download', function(){
return view('fileentries/download');
});
在
代码中执行文件下载后立即写入header(location: homepage.php);
。
您可以使用
url()
帮助程序函数。它将生成给定路径的完全限定 URL。此函数有三个参数:url($path,$parameters,$secure)
。在第一个参数中提供路由路径,在第二个参数中提供主题 ID。
表单开始标记应如下所示:
<form method="post" action="{{ URL('/download',$theme->id) }}">