在新窗口或选项卡中打开下载文件


open downloading file in new window or tab

我正在做一个joomla组件编程。我需要在新选项卡中打开我的下载文件。 文件下载的代码是:

<meta http-equiv="Refresh" content="3;URL=http://localhost/joomla/images/uploads/<?php echo $filee; ?> " >

我使用了这段代码而不是header("Content-Disposition: attachment; filename=".$filee.""); 是我需要在表单提交和下载开始之间的页面上显示一些消息。 标题不允许这样做。

下载适用于meta,但不是在当前窗口中打开文件,如何在新选项卡中打开它。??我尝试在此元标记之前提供带有 target=_blank 的表单标签,但没有用。

您要在新窗口或选项卡中打开的唯一方法是删除重定向并使用 target="_blank" 在感谢页面上添加指向该文件的链接。

经过多次搜索,我实现了在将请求重定向到其他页面后在新窗口中下载pdf文件的想法,分四个步骤-

1). Session::flash('myfileNameThatStoredInDb',  $orders->order_invoice);

2). 使用以下代码在控制器中创建一个函数

public function pdfDownload($image_url){
        header('Content-Type: application/octet-stream');
        header("Content-Transfer-Encoding: Binary");
        header("Content-disposition: attachment; filename='"" . basename($image_url) . "'"");
        readfile('Url('storage').'/invoice'.'/'.$image_url); 
    }

3). 为上述方法创建路由。

Route::get('/pdfdownload/{url}',"OrderController@pdfDownload");

4). 检查会话并在 HTML 文件标记中获取其值,并将其附加到控制器的方法路径中

@if(Session::has('download.in.the.next.request'))    
        <meta http-equiv="refresh" content="5; url={{ asset('pdfdownload/'.Session::get('download.in.the.next.request')) }}">
    @endif

注意-> 这段代码在 Laravel 中运行良好,我的目的只是给出一个想法。谢谢