Can I set the "HTML" Title of a PDF file served by my Apache Web server
I have HTML pa开发者_如何学Pythonges that contain <a> tags with hrefs that point to PDF files. My Apache Web server serves them just fine, but the title, as shown in the Browser history, is of the file name. I would like to be able to set that title.
Perhaps there's a Header than can be set?
I don't want to write a script to serve the files as the server can handle Content-Encoding negotiation (e.g., for gzip), and do flow control, none of such do I want to re-create.
Here is an http header you can set.
Content-Disposition:inline; filename="*File name you want*";
I suspect the issue you are having is that the client browser is storing the file name in the history, which you cannot fix.
Last I checked, the title in the history came from the setting of the HTML page (not a header), so there should be no HTTP header field for the title.
I am no HTTP expert and do not know all the fields, but I do not remember there being a setting in any server that I have ever worked with to set the page's title (just the status code, protocol, etc.)
I created a PHP-Skript (e.g. download.php, filename doesn't matter) like this:
<?php
header("Content-Type: application/pdf");
header('Content-Disposition: inline; filename="'.addslashes($_REQUEST['title']).'"'); //filename doesn't set the browser title here, only when page is saved/downloaded
$content = file_get_contents($_REQUEST['filename']);
header('Content-Length: '.strlen($content));
echo $content;
In my setup (Windows 10; Apache 2.4.37; PHP 7.1.25) you can now do a request like this: http://..../download.php/browser_title?filename=test.pdf
I tested this successfully in Chrome and Firefox. Internet Explorer was not able to display a PDF-Document inline :-/. Microsoft Edge also included the URL-Parameter in the title bar :-(.
精彩评论