dongwei1855 2012-10-19 22:46
浏览 20
已采纳

如何在PHP中将文件夹中的照片显示到网页中[关闭]

Picture a upload link used to up load JPEG, PNG, and GIF into a folder called /originals. Then a code standardizes the dimensions of the photos to a thumbnail and saves the new thumbnail in the /thumbnails folder.

How can I now display the thumbnail photo in an array in a 6 columned table in the webpage as soon as its uploaded?

My php block:

 <?php

$files = scandir("./."/thumbnails);
$numFiles = count($files);

 if($numFiles < 3)
{
echo "<p>Gallery is empty </p>";
}
else 
{
echo "<p> click thumbnail </p>";
echo "<table><tr>";
for($i = 0; $i < $numfiles -2; $i++)
{
    if($i % $Num_COLUMNS == 0 && $i != 0)
        {
            echo "</tr><tr>";
        }
    echo "<td>";
    echo "<a href='ViewPicture.php?src=".urlencode($files[i +2])."' target='_blank'><img src='".GALLERY_THUMBNAILS.urlencode($files[$i + 2])."' alt='".$files[$i + 2])."' title='".$files[$i + 2]."'/></a>'";
    echo "</td>";
}
echo "</tr> </table>";
}
?>
  • 写回答

1条回答 默认 最新

  • dongpi9494 2012-10-19 22:48
    关注

    Use the scandir function in PHP to get all files. Then loop through the result and output an <img> tag for each file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题