简体   繁体   中英

display images dynamically from folder using php

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 checkbox 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> ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM