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