Table of Contents
回复内容:
Home Backend Development PHP Tutorial readfile输出文件到浏览器页面,想要改变这个页面的title

readfile输出文件到浏览器页面,想要改变这个页面的title

Jun 06, 2016 pm 08:34 PM
html php file reading

<code>$pdf_name=basename($_SERVER['REQUEST_URI']);
$pdf_dir=registry("DOC_ROOT")."test/". $csrUid. "/" . $pdf_name;
if (!file_exists($pdf_dir)) {
    die ("文件不存在!") ;
}
//$pdf_dir = http://xxxx.com/test/test-2015/download.pdf
header("Content-type: application/pdf");
readfile($pdf_dir);   //  1
exit;
</code>
Copy after login
Copy after login

像上面所述,// 1 处输出在页面输出了pdf内容,但是页面的title没有变,我现在想把这个输出pdf的页面title改为$pdf_name的值,用了ob_start()/ob_end_flush()/echo "

$pdf_name"; ,还是失败了,不能改变这个title。
求解该怎么书写呢?

回复内容:

<code>$pdf_name=basename($_SERVER['REQUEST_URI']);
$pdf_dir=registry("DOC_ROOT")."test/". $csrUid. "/" . $pdf_name;
if (!file_exists($pdf_dir)) {
    die ("文件不存在!") ;
}
//$pdf_dir = http://xxxx.com/test/test-2015/download.pdf
header("Content-type: application/pdf");
readfile($pdf_dir);   //  1
exit;
</code>
Copy after login
Copy after login

像上面所述,// 1 处输出在页面输出了pdf内容,但是页面的title没有变,我现在想把这个输出pdf的页面title改为$pdf_name的值,用了ob_start()/ob_end_flush()/echo "

$pdf_name"; ,还是失败了,不能改变这个title。
求解该怎么书写呢?

你输出的内容是 application/pdf 类型的, 所以浏览器拿什么内容做标题, 你是没办法通过输出 <title></title>来控制的.

目前实验的结果是:
chrome 在显示 pdf文件时, 标题是显示的URL地址.
IE 是直接显示下载的(如果安装的有PDF阅读的插件不排除是直接显示,而非下载的情况).
Firefox 在加载中的时候,显示的是PDF的文件名, 加载完成之后,显示的是PDF中的标题.
以这个URL为例: http://www.st.com/web/en/resource/technical/document/datasheet/CD00001...
Chrome:
readfile输出文件到浏览器页面,想要改变这个页面的title

IE:
readfile输出文件到浏览器页面,想要改变这个页面的title
Firefox:
readfile输出文件到浏览器页面,想要改变这个页面的title

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

HTML Table Layout

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles