0

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

?>
3
  • Please edit your post and make your PHP code was displayed as a code. Commented Feb 15, 2010 at 6:19
  • If you want them in columns, you can always use a table. Or have fun aligning them with CSS. This code is a mess though. Commented Feb 15, 2010 at 6:21
  • By the way Patel this question should be tagged in PHP Commented Feb 15, 2010 at 6:24

3 Answers 3

3

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

?>
Sign up to request clarification or add additional context in comments.

Comments

2

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

?>

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.