dongyi4420 2019-02-28 12:07
浏览 142
已采纳

获取每个文件的文件名的文件创建日期,而不仅仅是1个文件?

I currently have the setup below. Want I want it to do is to to scan 3 directories, display all files (up to 12) in each for each directory. In the filename name column I want it to display the file creation date for each file. However, it's only looping over the creation date for either 1 file or the index.php file rather than looking in the directories folder? Can anyone assist please?

<?php
date_default_timezone_set('Europe/London');
$dirname = "dir1";
$dirnameTwo = "dir2";
$dirnameThree = "dir3";

$cam1 = scandir($dirname, 1);
$cam2 = scandir($dirnameTwo, 1);
$cam3 = scandir($dirnameThree, 1);
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html>
<head>
    <meta http-equiv='refresh' content='10'>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <meta http-equiv='cache-control' content='max-age=0' />
    <meta http-equiv='cache-control' content='no-cache' />
    <meta http-equiv='expires' content='0' />
    <meta http-equiv='expires' content='Tue, 01 Jan 1980 1:00:00 GMT' />
    <meta http-equiv='pragma' content='no-cache' />
</head>

<body>
<style type="text/css">
    .pi-title {
        padding: 1rem;
    }
</style>
<div class="container">
    <div class="row">
        <div class="pi-title">
            <h3>Test</h3>
        </div>
        <div class="table-container col-md-12">
            <table class="table" border='1' cellpadding='5' cellspacing='0' bordercolor='#ccc'>
                <thead class="thead-dark">
                <tr>
                    <th scope="col">ID</th>
                    <th scope="col">File Name</th>
                    <th scope="col">1 </th>
                    <th scope="col">2</th>
                    <th scope="col">3</th>
                </tr>
                </thead>
                <tbody>
                <tr></tr>
                <tr>
                    <?php
                    error_reporting(E_ALL & ~E_NOTICE);
                    $directories = implode(',', [ $dirname, $dirnameTwo, $dirnameThree]);
                    $items = (glob("./{{$directories}}/*", GLOB_BRACE));
                    array_multisort(array_map('filemtime', $items),SORT_NUMERIC,SORT_DESC, $items);
                    $dirs = array($dirname, $dirnameTwo, $dirnameThree);
                    foreach ($items as $filename) {
                                    for ($i = 1; $i <= 12; $i++) {
                                    if (file_exists($filename)) {
                                        echo "</tr>";
                                        echo "<td><font face='Arial' size='6'>$i</font></td>";
                                        echo "<td><font face='Arial' size='6' color='red'>" . date("F d Y H:i", filemtime($filename));
                                        echo "</font></td>";
                                    }
                                    print("

                                               <td><img src='$dirs[0]/$cam1[$i]' height='180' width='220'></td>
                                               <td><img src='$dirs[1]/$cam2[$i]' height='180' width='220'></td>
                                               <td><img src='$dirs[2]/$cam3[$i]' height='180' width='220'></td>

                           ");
                           if ($i === 12) break;
                           }
                        if ($i === 12) break;
                    }
                    ?>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • duanan6043 2019-02-28 13:17
    关注

    Replace the whole foreach loop with this.

    for ($i = 1; $i <= 12; $i++) {
        if (file_exists($items[$i])) {
            echo "</tr>";
            echo "<td><font face='Arial' size='3'>$i</font></td>";
            echo "<td><font face='Arial' size='3' color='red'>" . date("F d Y H:i", filemtime($items[$i]));
            echo "</font></td>";
        }
        print("
    
               <td><img src='$dirs[0]/$cam1[$i]' height='80' width='80'></td>
               <td><img src='$dirs[1]/$cam2[$i]' height='80' width='80'></td>
               <td><img src='$dirs[2]/$cam3[$i]' height='80' width='80'></td>
    
       ");
       if ($i === 12) break; //unnecessary should/could be removed
     }
    

    Replaced $filename with $items[$i]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器