开发者

display images dynamically from folder using php

开发者 https://www.devze.com 2022-12-20 00:05 出处:网络
i am new to php i am working on image upload to folder and displaying it from the same folder and added checkbox to each diasplayed image.. but my problem is images are displaying one below the other

i am new to php i am working on image upload to folder and displaying it from the same folder and added checkbox to each diasplayed image.. but my problem is images are displaying one below the other but i want to diasply each image and the corresponding ch开发者_StackOverflow社区eckbox in sperate column can any one pls help me out in this thanks in advance.. here is my code.

<?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);

?>


I think you need to do the following

<?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);

?>


you can use table here

<?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);

?>


Depending on what you're trying to achieve, you could display a table or definitions list.

<table>
    ...
    <tbody>
         <tr>
              <td>checkbox here</td>
              <td>image here</td>
         </tr>
         ...
    ...
</table>

<!-- or -->

<dl>
    <dt>image here</dt>
    <dd>checkbox here</dt>
</dl>

So simply display the beginning of the table/list (<table><thead>....<tbody>/<dl>) then display in loop your images with checkboxes

while (...) {
    ...
    echo '<dt>image</dt><dd>checbox</dd>'); //or a table row
}

Finally display the ending of table/list (</tbody></table>/</dl>).

0

精彩评论

暂无评论...
验证码 换一张
取 消