繁体   English   中英

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

[英]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); 
?>

暂无
暂无

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

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