Home >Backend Development >PHP Tutorial >How to use php to make the browser directly download pdf files_PHP tutorial

How to use php to make the browser directly download pdf files_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:25:061038browse

Some browsers have a pdf opening program installed and associated with the browser, so when directly writing the pdf path, the pdf will be opened instead of downloaded. Now I will talk about how to let them just download instead of browse.

Create a php file

Copy the code The code is as follows:

$file = $_GET['file'];
$arr = explode('/',$file);
header('Content-type: application/pdf');
header( 'Content-Disposition: attachment; filename="'.array_pop($arr).'"');
readfile(file);
?>


Join The code, through this, converts the pdf path into a language recognized by the browser and tells the browser
liezi/upload.php?file=/aa/aa.pdf
so that no matter what it is, it will be downloaded instead of Open

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825213.htmlTechArticleSome browsers have a pdf opening program installed and associated with the browser, so when you write the pdf path directly, the pdf is opened. Instead of downloading, let me talk about how to let them just download instead of browsing...
Statement:
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