我有一个工作代码,可以读取目录并输出name
,total files
和size
。我想要做的是抓取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>";
}
}
}
}
答案 0 :(得分:3)
if (file_exists($filename)) {
echo "$filename was last modified: " . date ("Y-m-d", filemtime($filename));
}