在 5 列中显示文件夹中的图像


Display images from folder in 5 columns

嗨,我

正在查看要删除的文件夹中的文件,现在工作正常,但图像在一个列表中,我想在 5 列中显示图像,我尝试添加一个表格但根本无法让它工作,有什么想法吗? 这是我的代码

<form id="stallionidelete" method="post" enctype="multipart/form-data">
<?php
$dir = dirname(__FILENAME__)."/images/gallery" ;
$files1 = scandir($dir);
foreach($files1 as $file) {
    if(strlen($file) >=3) {
        $foil = strstr($file, 'jpg'); // As of PHP 5.3.0
        $foil = $file;
        $pos = strpos($file, 'css');
        if ($foil==true) {
            $i == ++$i;
            echo '<table><tr>';
            echo '<div class="gimage_'.$i.'"><input type="checkbox" id="gimage_'.$i.'" name="filenames['.$i.'][]" value="'.$foil.'" />';
            echo "<img width='150' height='150' src='images/gallery/$file' /><br/></div>";
            echo '</tr></table>';
            // for live host
            //echo "<img width='130' height='38' src='/ABOOK/SORTING/gallery-dynamic/images/gallery/$file' /><br/>";
        }
    }
}
?>
<input type="submit" name="mysubmit2" value="Delete">
</form>

我认为像下面这样的东西会有所帮助。

$dir = dirname(__FILENAME__)."/images/gallery" ;
$files1 = scandir($dir);
if ($files1) {
    echo '<table>';
    $fileCount = 0;
    foreach($files1 as $file){
        if(strlen($file) >=3 && strstr($file, 'jpg')){
            if ($fileCount % 4 == 0) {
               if ($fileCount > 0) {
                   echo '</tr>';
               }
               echo '<tr>';
            }
            echo '<td>
                     <input type="checkbox" id="gimage_'.$i.'" name="filenames['.$i.'][]" value="'.$foil.'" />
                     <img width="150" height="150" src="images/gallery/'.$file.'" />
                  </td>';
            $fileCount++;
        }
    }
    if ($fileCount > 0){
        if ($fileCount % 4 > 0){
            echo '<td colspan="'.($fileCount%4).'"></td>';
        }
        echo '</tr>';      
    }
    echo '</table>';
    echo '<input type="submit" name="mysubmit2" value="Delete">';
}

这就是你应该如何做代码

    <form id="stallionidelete" method="post" enctype="multipart/form-data">
   <table border='1' width='546' cellspacing='0' cellpadding='0' bordercolor="#E1F5FF">
<tr>
            <td>
            <table  summary='table' style="width: 797px">
    <thead id="start">
        <tr>
            <th width='150' style="height: 40px">Image1</th>
            <th width='150' style="height: 40px">image2</th>
             <th width='150' style="height: 40px">Image3</th>
            <th width='150' style="height: 40px">image4</th>
             <th width='150' style="height: 40px">image5</th>
            </tr>
    </thead>
        <tfoot>
    </tfoot>
    <tbody>
<tr>
        <?php
        $dir = dirname(__FILENAME__)."/images/gallery" ;
        $files1 = scandir($dir);
        foreach($files1 as $file){
        if(strlen($file) >=3){
        $foil = strstr($file, 'jpg'); // As of PHP 5.3.0
        $foil = $file;
        $pos = strpos($file, 'css');
        if ($foil==true){
        $i == ++$i;
        echo '<td bgcolor="#F7F7F7" width="183">';
        echo '<div class="gimage_'.$i.'"><input type="checkbox" id="gimage_'.$i.'" name="filenames['.$i.'][]" value="'.$foil.'" />';
        echo "<img width='150' height='150' src='images/gallery/$file' /><br/></div>";
        echo '</td>';
         // for live host
        //echo "<img width='130' height='38' src='/ABOOK/SORTING/gallery-dynamic/images/gallery/$file' /><br/>";
        }
        }
        }?>
        </table>
    </tr>  
        </tbody>
    </table></td>
            </tr>
        </table>
        </form>
        <input type="submit" name="mysubmit2" value="Delete">

你不必回显表,你也忘记放<td>tag</td>

我想在这里缩短误解,你能基本检查一下,告诉我这是否需要