我想制作一个具有 pdf 下载选项的网页,但我希望它受到密码保护,即如果有人点击该链接,他必须输入用户名和密码,并且如果他直接打开链接“www.example.com/~folder_name /abc.pdf" 然后服务器首先要求输入密码然后允许下载
编辑:我希望用户在浏览器中查看文件,而不是强制下载这是我的代码
<?php
/* authentication script goes here*/
$file = 'http://example.com/folder_name/abc.pdf';
//header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
//header('Expires: 0');
//header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
//header('Pragma: public');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file);
?>
但是这段代码没有在我的浏览器中打开 pdf。我不希望代码依赖于浏览器使用的 pdf 插件