如何通过提示“另存为”对话框从网页中保存文件


How to save a file from webpage by prompting save as dialog box?

在我的应用程序中,单击超链接后,应用程序会创建一个PDF文件并自动下载,而不会提示保存该文件。我需要一个Save As对话框,提示在本地保存文件,这样我每次下载文件时都可以选择一个目录。请帮我解决这个问题。谢谢

我认为这取决于浏览器的支持,如果浏览器支持查看文件,那么你可以在浏览器中看到文件并点击保存按钮下载,否则,浏览器会提示一个对话框。

试试这个。。。愿帮助你。。。

<a href="pdf_server.php?file=file_path">Download</a>
pdf_server.php
<?php
header("Content-Type: application/octet-stream");
$file = $_GET["file"] .".pdf";
header("Content-Disposition: attachment; filename=" . urlencode($file));   
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");            
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
    echo fread($fp, 65536);
    flush(); // this is essential for large downloads
} 
fclose($fp); 
?>