我能够选择和显示的图像,但我需要它显示为链接,然后在点击链接下载它
$imagesDirectory =basename("images/"); //path to directory
if (is_dir($imagesDirectory))
{
$opendirectory = opendir($imagesDirectory); // to read images from path
while (($image = readdir($opendirectory)) !== false)
{
if(($image == '.') || ($image == '..'))
{
continue;
}
$imgFileType = pathinfo($image,PATHINFO_EXTENSION);
if(($imgFileType == 'jpg') || ($imgFileType == 'png')) //Types of files
{
echo "<img src='images/".$image."' width='200'> ";
}
}
closedir($opendirectory);
}
?>发布于 2018-05-30 14:05:07
您已经非常接近答案了,只需将图像包装在锚定标记中并将"download“属性传递给它即可。就是这样:
$imagesDirectory =basename("images/"); //path to directory
if (is_dir($imagesDirectory))
{
$opendirectory = opendir($imagesDirectory); // to read images from path
while (($image = readdir($opendirectory)) !== false)
{
if(($image == '.') || ($image == '..'))
{
continue;
}
$imgFileType = pathinfo($image,PATHINFO_EXTENSION);
if(($imgFileType == 'jpg') || ($imgFileType == 'png')) //Types of files
{
/*xxxxxxxxxxxx-----Here's the Change-----xxxxxxxxxxxx*/
echo "<a href='images/".$image."' download><img src='images/".$image."' width='200'> </a>";
}
}
closedir($opendirectory);
}
?>https://stackoverflow.com/questions/50597225
复制相似问题