[英]display images dynamically from folder using php
我是php的新手,正在处理将图片上传到文件夹并从同一文件夹显示它,并向每个显示的图像添加复选框的问题。但是我的问题是图像在另一个下方显示一个,但是我想仔细检查每个图像及其对应的图像sperate列中的复选框是否可以在此先感谢我。.这是我的代码。
<?php
$path = "small";
$dir_handle = @opendir($path) or die("Unable to open folder");
while (false !== ($file = readdir($dir_handle))) {
if($file != '.' && $file != '..' && $file != 'Thumbs.db')
{
echo "<input type=CHECKBOX name=$file>";
echo "<img src='small/$file' alt='$file'><br />";
}
}
closedir($dir_handle);
?>
我认为您需要执行以下操作
<?php
$path = "uploads";
$dir_handle = @opendir($path) or die("Unable to open folder");
echo "<table>";
echo"<tr>";
while (false !== ($file = readdir($dir_handle))) {
if($file != '.' && $file != '..' && $file != 'Thumbs.db'){
echo "<td><input type=CHECKBOX name=$file></td>";
echo "<td><img src='uploads/$file' alt='$file'><br>
$file
</td>";
}
}
echo"<tr/>";
echo"</table>";
closedir($dir_handle);
?>
你可以在这里用桌子
<?php
$path = "small";
$dir_handle = @opendir($path) or die("Unable to open folder");
echo "<table>";
while (false !== ($file = readdir($dir_handle))) {
if($file != '.' && $file != '..' && $file != 'Thumbs.db')
{
echo"<tr>";
echo "<td><input type=CHECKBOX name=$file></td>";
echo "<td><img src='small/$file' alt='$file'></td>";
echo"<tr/>";
}
}
echo"</table>";
closedir($dir_handle);
?>
根据您要实现的目标,可以显示表或定义列表。
<table>
...
<tbody>
<tr>
<td>checkbox here</td>
<td>image here</td>
</tr>
...
...
</table>
<!-- or -->
<dl>
<dt>image here</dt>
<dd>checkbox here</dt>
</dl>
因此,只需显示表/列表的开头( <table><thead>....<tbody>
/ <dl>
),然后使用复选框循环显示图像
while (...) {
...
echo '<dt>image</dt><dd>checbox</dd>'); //or a table row
}
最后显示表/列表的结尾( </tbody></table>
/ </dl>
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.