php读取目录并修改文件夹的输出日期

时间:2012-03-09 14:02:20

标签: php mysql readdir

我有一个工作代码,可以读取目录并输出nametotal filessize。我想要做的是抓取Date Modified并将其格式化为YYYY-MM-DD

代码:

if ($handle = opendir('D:/'.$sub.'/')) {

    while (false !== ($entry = readdir($handle))) {
        if ($entry != '$RECYCLE.BIN' && $entry != 'System Volume Information' && $entry != '.' && $entry != '..') {
        $exists = mysql_query('SELECT * FROM comics WHERE arc LIKE "'.$entry.'%"');
        $exists1 = mysql_num_rows($exists);
            if ($exists1 == 0) {
            $directory = $base.$sub."/".$entry;
            $filecount = count(glob($directory."/"."*.*"));
            $size = 0; 
            $d = new RecursiveIteratorIterator( 
            new RecursiveDirectoryIterator($directory),  
            RecursiveIteratorIterator::SELF_FIRST 
            ); 

            foreach($d as $file){ 
            $size += $file->getSize(); 
            } 

            $entry = str_replace(" - ", ": ", $entry);
                mysql_query('INSERT INTO comics (arc, files, size) VALUES ("'.$entry.'\n", "'.$filecount.'", "'.$size.'")');
                print "<li>Inserted <b>".$entry."</b> With A File Count Of <b>".$filecount."</b> & A Total Size Of <b>".$size."</b> Bytes.</li>";
            }
        }
    }
}

1 个答案:

答案 0 :(得分:3)

if (file_exists($filename)) {
    echo "$filename was last modified: " . date ("Y-m-d", filemtime($filename));
}

http://php.net/manual/en/function.filemtime.php