gpt4 book ai didi

php - 如何从文件夹中下载所有图像

转载 作者:行者123 更新时间:2023-11-28 03:53:04 25 4
gpt4 key购买 nike

我正在通过 Apache 服务器显示图像。当我点击每张图片时,它应该打开 download.php?fiel=file_name.jpg 并将图片下载到系统。

这是图片显示的代码

  <?php
$files = glob("Image/"."*.*");
for ($i=0; $i<count($files); $i++)
{
$num = $files[$i];
echo $num."<br>";
echo '<img src="'.$num.'" alt="Here should be image" width="256" height="192" >'."<br/>";
}
?>

我使用以下代码下载图像(即 download.php 文件)。

 <?php
$file = $_GET['file'];
header("Content-type: image");
header("Content-disposition: attachment; filename= ".$file."");
readfile($file);
?>

如何实现?

最佳答案

你的意思是这样的? :

<?php
$files = glob("Image/"."*.*");
$countFiles = count($files); //Don't do calculations in your loop, this is really slow

for ($i=0; $i<$countFiles; $i++)
{
$num = $files[$i];

echo '<a href="download.php?file=' . $files[$i] . '"><img src="'.$num.'" alt="Here should be image" width="256" height="192" ></a><br/>';
}
?>

关于php - 如何从文件夹中下载所有图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13739475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com