Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php、html显示表中文件夹中的图像?_Php_Image_Directory_Tabular - Fatal编程技术网

使用php、html显示表中文件夹中的图像?

使用php、html显示表中文件夹中的图像?,php,image,directory,tabular,Php,Image,Directory,Tabular,我想以表格形式显示我的图像。这是我的密码: <?php $files = glob("images/*.*"); for ($i = 0; $i < count($files); $i++) { $image = $files[$i]; $supported_file = array( 'gif', 'jpg', 'jpeg', 'png' ); $ext = strtolower(pa

我想以表格形式显示我的图像。这是我的密码:

<?php
$files = glob("images/*.*");
for ($i = 0; $i < count($files); $i++) {
    $image = $files[$i];
    $supported_file = array(
        'gif',
        'jpg',
        'jpeg',
        'png'
    );

    $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
    if (in_array($ext, $supported_file)) {
        echo basename($image);
echo '<img src="' . $image . '" alt="Random image" ,width=100px, height=100px /><br>';
} else {
continue;
}
}
?>


有点像那幅画

如果希望它出现在表中,只需将表标记与和一起添加到表中即可

<table>
<tr>
  <th>Image Name</th>
  <th>Image</th>
</tr>
<?php
$files = glob("images/*.*");
for ($i = 0; $i < count($files); $i++) {
    $image = $files[$i];
    $supported_file = array(
        'gif',
        'jpg',
        'jpeg',
        'png'
    );

    $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
    if (in_array($ext, $supported_file)) {
      echo "<tr><td>";
      echo basename($image);
      echo "</td><td>";
      echo '<img src="' . $image . '" alt="Random image" ,width=100px, height=100px /><br>';
      echo "</td></tr>";
} else {
continue;
}
}
?>
</table>

图像名称
形象

从以下位置更改html代码:

echo'
'

echo”“;
回声“;
echo basename($image);
回声“;
回声';
回声“;
回声“;

只需创建表标记,
使用
for
循环迭代图像是一种有效的方法,但您忘记了将表结构添加到输出中。否则,浏览器将无法渲染任何表。我建议您阅读几行关于如何在html标记中定义表的内容。您使用表格元素(行和单元格)定义表格,然后在单元格内像以前一样输出图像。实际输出是什么?您的另一个想法可能是PHP使用文件系统的文件路径(绝对路径),而HTML使用相对于文档根的路径。因此,您需要将PHP路径转换为HTML可以使用的路径。谢谢您的回答。帮助我很多。:)谢谢你的回答。帮助我很多。:)
  echo "<table border='1'>";
  echo "<tr><td>";
  echo basename($image);
  echo "</td><td>";
  echo '<img src="' . $image . '" alt="Random image" ,width=100px, height=100px />';
  echo "</td></tr>";
  echo "</table>";