我们的网络应用程序使用网址中的.pdf#[destination]在特定点开放的网络驱动器上提供.pdf文件的下载链接。
到目前为止,这一切工作正常 - 但在新项目中,我们无法保证客户端拥有网络驱动器的用户权限。
因此,该方法可能是php提供下载的某种方式:
<?php
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile('///share/folder/original.pdf');
?>
但是我们如何为这样的下载添加#[目标标签] - 这有可能吗?
答案 0 :(得分:0)
我们最终这样做了。
网络服务器需要以具有网络共享读取权限的用户身份运行。
使用GET函数openfilefromshare.php?filepath=//192.168.x.x/share/this.pdf&#page=xxxx
$fullPath = $_GET['filepath'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
header("Content-type: application/octet-stream");
header("Content-Disposition: inline;filename=\"".$path_parts["basename"]."\"");
header("Content-length: $fsize");
header("Cache-control: private");
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
echo $fsize;
fclose ($fd);