我们的web应用程序提供网络驱动器上.pdf文件的下载链接,该驱动器在特定点使用url中的.pdf#[destination]打开。
到目前为止,这一直运行良好,但在一个新项目中,我们不能保证客户端拥有网络驱动器的用户权限。
因此,这种方法可能是php,它为下载提供某种:
<?php
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile('///share/folder/original.pdf');
?>
但是,我们如何为这样的下载添加#[目的地标签]?这可能吗?
我们最终是这样做的。
Web服务器需要以具有网络共享读取权限的用户身份运行。
使用GET函数openfilefromshare.php?filepath=//192.168.x.x/share/this.pdf&#page=xxxx
,url可以如下所示
$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);