如何从服务器下载文件并使用对话框保存

时间:2019-02-14 08:14:53

标签: javascript download dialog

我正在尝试从目标server下载文件,收到文件后,我想打开一个对话框,让我选择保存位置。

到目前为止,我仅用于简单下载:

<a class="button" type="application/octet-stream"  href="http://localhost:5300/get" download>Click here for dld</a>

我已阅读到我需要使用FileApi来实现此目的,但是仍然不能在所有浏览器中使用。

我如何设法打开对话框?

2 个答案:

答案 0 :(得分:1)

只需使用

<?php ob_end_clean(); $filePath = 'P:\niks\all Zip Files\Reports\Report 01 feb 2019.zip'; header('Content-Description: File Transfer'); header('Content-Type: application/force-download'); header("Content-Disposition: attachment; filename=\"" . basename($filePath) . "\";"); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filePath)); readfile($filePath);

答案 1 :(得分:1)

尝试使用有助于处理下载操作的jquery.fileDownload.js

  

http://jqueryfiledownload.apphb.com/