我创建了一个 PHP 页面,允许用户在单击此链接时下载文件:
<a href="download_pdf.php?pubid=<?php echo $row_rsPublications['pubID']; ?>&file=<?php echo $row_rsPublications['file']; ?>">Download File</a>
我还创建了链接指向的下载页面:
<?php
if(isset($_GET['file'])) {
$fileID = $_GET['pubid'];
$filename= ($_GET['file']);
$path = "admin/pubfiles/";
$fullPath = $path . $filename;
mysql_select_db($database_connDioceseofife, $connDioceseofife);
$sql = "SELECT file FROM publications WHERE pubID = $fileID";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if($filename == NULL) {
die('No file exists or the name is invalid!');
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
readfile($fullPath);
}
?>
现在我的问题是,当下载弹出窗口出现时,它读取文件是 0 字节。而且下载的时候打不开。我收到消息,它不是受支持的文件类型,或者它已损坏或损坏。
请任何帮助将不胜感激。