强制打开“另存为…”弹出打开文本链接,单击HTML中的PDF格式

强制打开“另存为…”弹出打开文本链接,单击HTML中的PDF格式

我有一些大的PDF目录在我的网站,我需要链接这些下载。当我在google上搜索时,我发现下面有这样一个东西。它应该打开“但作为.。“在链接点击弹出.。

 <head>
    <meta name="content-disposition" content="inline; filename=filename.pdf">
    ...

但是它不起作用:/当我按下面的方式链接到一个文件时,它只是链接到文件并试图打开该文件。

    <a href="filename.pdf" title="Filie Name">File name</a>

最新情况(根据以下答复):

正如我所看到的,没有100%可靠的跨浏览器解决方案。最好的方法可能是使用下面列出的Web服务之一,并提供一个下载链接.


饮歌长啸
浏览 761回答 3
3回答

红颜莎娜

从答案到在单击链接后强制浏览器保存文件:<a&nbsp;href="path/to/file"&nbsp;download>Click&nbsp;here&nbsp;to&nbsp;download</a>

ITMISS

<a&nbsp;href="file&nbsp;link"&nbsp;download&nbsp;target="_blank">Click&nbsp;here&nbsp;to&nbsp;download</a>它适用于我在Firefox和Chrome中。

梦里花落0921

元标记不是实现这一结果的可靠方法。通常,您甚至不应该这样做-应该由用户/用户代理来决定如何处理所提供的内容。如果用户愿意的话,总是可以强迫他们的浏览器下载文件。如果仍然希望强制浏览器下载文件,请直接修改HTTP头。下面是一个PHP代码示例:$path = "path/to/file.pdf";$filename = "file.pdf";header('Content-Transfer-Encoding: binary');&nbsp; // For Gecko browsers mainlyheader('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');header('Accept-Ranges: bytes');&nbsp; // Allow support for download resumeheader('Content-Length: ' . filesize($path));&nbsp; // File sizeheader('Content-Encoding: none');header('Content-Type: application/pdf');&nbsp; // Change the mime type if the file is not PDFheader('Content-Disposition: attachment; filename=' . $filename);&nbsp; // Make the browser display the Save As dialogreadfile($path);&nbsp; // This is necessary in order to get it to actually download the file, otherwise it will be 0Kb请注意,这只是HTTP协议的一个扩展;有些浏览器可能会忽略它。
打开App,查看更多内容
随时随地看视频慕课网APP