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

WBOY
Release: 2016-07-13 10:25:06
Original
991 people have browsed it

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...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!