简体   繁体   English

如何使用php渲染pdf文件

[英]How to render pdf file by using php

We have some PDF files and instead of giving direct link to to file, we want it to render through php so that only authenticated users are able to download the pdf file. 我们有一些PDF文件,而不是直接链接到文件,我们希望它通过php呈现,以便只有经过身份验证的用户才能下载pdf文件。 Thus we dont need to give filepath to user. 因此,我们不需要将文件路径提供给用户。

Is it possible? 可能吗?

Mangesh 芒格什

You can, here is a sample: 您可以,这里是一个示例:

<?php
$file = './path/to/the.pdf';
$filename = 'You dont know where I am.pdf';

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');

@readfile($file);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM