简体   繁体   English

文件下载被浏览器弹出窗口阻止程序阻止

[英]File download is being blocked by the browser popup blocker

I have a file download function in php that calls the download file, but the browser popup blocker is preventing it from opening. 我在php中有一个文件下载功能,该功能会调用下载文件,但是浏览器弹出窗口阻止程序阻止了它的打开。

The goal is to have an html form submit button which submits a form, edits an rtf file on the server based on the form inputs, then downloads the new file to the user. 目的是要有一个html表单提交按钮,该按钮提交一个表单,根据表单输入在服务器上编辑rtf文件,然后将新文件下载给用户。

Because I need php to run some code after the user clicks download and before the file is downloaded I couldn't get it to work any other way. 因为在用户单击下载之后并且在下载文件之前,我需要php来运行一些代码,所以我无法使其以任何其他方式工作。 I had to make php echo a link, then some js code that clicks that link. 我必须使php回显一个链接,然后单击该链接的一些js代码。

The download function: 下载功能:

function download($path, $name){
if(!file_exists($path)){
    echo $path." does not exist.";
}
else{
    echo "
<a href='download.php?path={$path}&name={$name}' id='download' 
target='download_frame' style='display:none;'>Download File</a>
<script>document.getElementById('download').click();</script>
    ";
    }
}

download.php: 的download.php:

<?php
header("Content-type: application/doc");
basename($_GET["path"]));
$name = $_GET["name"];
header("Content-Disposition: attachment; filename='".$name.".doc");
header("Content-Transfer-Encoding: quoted_printable");
header('Pragma: no-cache');
header('Expires: 0');

header("Cache-Control: public");
header("Content-Description: File Transfer");

header('Content-Transfer-Encoding: binary');
header("Content-type: application/force-download");
header('Content-Type: application/octet-stream');

readfile($_GET["path"]);

You can do a header in place of echo and using JavaScript : 您可以使用JavaScript来代替header的标头:

header ('location: download.php?path='. $path .'&name='. $name);

This will redirect to the download.php in same page and propose to download the file. 这将重定向到同一页面中的download.php并建议下载文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 浏览器弹出窗口阻止程序阻止的打印窗口 - Print window blocked by browser popup blocker 如何阻止我的Facebook共享窗口被弹出窗口阻止程序阻止? - How do I stop my Facebook share window from being blocked by popup-blocker? 从没有弹出窗口阻止程序的预签名 URL 下载 S3 文件 - Download S3 file from pre-signed URL without popup blocker 如何测试打开的命名窗口或被弹出窗口阻止程序阻止的命名窗口? - How can I test if a named window is opened or was blocked by a popup blocker? IE弹出窗口阻止程序阻止了Javascript window.open - Javascript window.open is blocked by IE popup blocker 为什么twitter bookmarklet不被弹出窗口拦截器阻止? - Why does twitter bookmarklet does not get blocked by popup blocker? 如何在没有弹出窗口阻止程序的情况下将PDF下载到新的选项卡/窗口? - How to download a PDF to a new tab/window without popup blocker? 绕过iOS Safari /任何移动浏览器上的弹出窗口阻止程序 - Bypassing popup blocker on iOS Safari / any mobile browser 阻止子窗口被弹出窗口拦截器捕获 - prevent child window from being caught by popup blocker 以编程方式确定是否在浏览器中启用了弹出窗口阻止程序,而无需打开新选项卡 - programmatically determine if the popup blocker is enabled in a browser without opening the new tab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM