我的服务器上有一个 pdf 文件。我想创建这样的链接,用户可以单击它并下载该 pdf 文件。我正在使用 Zend 框架与 Php 一起工作。
将此代码放入 php 文件中并将其命名为 f.e. “下载.php”:
<?php
$fullPath = "path/to/your/file.ext";
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
header("Content-length: $fsize");
header("Cache-control: private");
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
?>
示例:将此类链接放入提供文件下载的文档中:
<a href="download.php?download_file=some_file.pdf">Download here</a>
更多详情:
http://www.finalwebsites.com/forums/topic/php-file-download http://www.finalwebsites.com/forums/topic/php-file-download
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)