Home >Backend Development >PHP Tutorial >PHP makes the browser download the pdf instead of opening it_PHP tutorial

PHP makes the browser download the pdf instead of opening it_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:48:581262browse

This article will introduce to you how to allow users to open PDF files instead of browsing them directly in the browser but directly downloading the PDF files to the client in the form of downloaded files.

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

Create a php file

 代码如下 复制代码
$file = $_GET['file'];
$arr = explode(‘/’,$file);
header(‘Content-type: application/pdf’);
header(‘Content-Disposition: attachment; filename=”‘.array_pop($arr).’”‘);
readfile(file);
?>

Add code to convert the pdf path into a language recognized by the browser and tell the browser
Liezi /upload.php?file=/aa/aa.pdf
In this way, no matter what it is, it will be downloaded instead of opening

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632761.htmlTechArticleThis article will introduce to you how to let users open pdf files instead of browsing directly in the browser but downloading them directly. The pdf file is downloaded to the client in file format. Some browsers have it installed...
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