How to render pdf file by using php

馋奶兔 提交于 2020-01-25 13:14:46

问题


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. Thus we dont need to give filepath to user.

Is it possible?

Mangesh


回答1:


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);
?>


来源:https://stackoverflow.com/questions/21566450/how-to-render-pdf-file-by-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!