我正在使用下面的代码将图像下载到我的硬盘。通过使用我放在新闻页面中的第一个链接,我可以下载图像。我放在图库中的第二个链接不起作用。路径是正确的,我打开了一个没有downlaod.php文件的图像,路径没有错误,但图像没有下载。我使用不同的图像 ID 尝试了不同的图像,但它不适用于该特定页面
<a href="<?php echo SITE; ?>download.php?filename=<?php echo SITE; ?>uploads/news/<?php echo $rowimg['image']; ?>" title="download">
下载图像
<a href="<?php echo SITE; ?>download.php?filename=<?php echo SITE; ? >uploads/gallery/<?php echo $row['folder']; ?>/<?php echo $row1['folder']; ?>/<?php echo $row2['folder']; ?>/<?php echo $rowimg['image']; ?>" title="Download">
download</a>
错误是:文件可能已损坏或太大
下载.php
<?php
$filename = $_GET["filename"];
$buffer = file_get_contents($filename);
/* Force download dialog... */
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Type: application/image");
/* Don't allow caching... */
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
/* Set data type, size and filename */
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . strlen($buffer));
header("Content-Disposition: attachment; filename=$filename");
/* Send our file... */
echo $buffer;
?>