简体   繁体   中英

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

In my application, after clicking on a hyperlink, the application creates a PDF file and downloads it automatically without prompting to save the file. I need a Save As dialog box prompting to save the file locally, that way I can select a directory every time I download the file. Please help me out with this. Thanks.

我认为这取决于浏览器的支持,如果支持浏览器来查看文件,则可以在浏览器中看到文件,然后单击“保存”按钮将其下载,否则,浏览器将提示一个对话框。

Try This... May Help You...

<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); 
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM