目前我可以列出目录中的所有文件。我正在使用此代码,它工作正常:
<?php
if ($handle = opendir('./uploaded')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo '<div class="col-md-3"><div class="panel panel-default"><!-- Default panel contents --><div class="panel-heading">'.$entry.'</div><div class="panel-body">'.$entry.'</div><div class="panel-footer"><a href="./uploaded/'.$entry.'">View File</a></div></div></div>';
}
}
closedir($handle);
}
?>
现在我想在while部分显示有关该文件的所有信息。我见过人们使用C和其他语言的类似技术来做到这一点。
答案 0 :(得分:2)
请尝试fstat了解更多详情
描述¶
<?php
// open a file
$fp = fopen("/etc/passwd", "r");
// gather statistics
$fstat = fstat($fp);
// close the file
fclose($fp);
// print only the associative part
print_r(array_slice($fstat, 13));
?>
收集文件指针句柄打开的文件的统计信息。此函数类似于Array
(
[dev] => 771
[ino] => 488704
[mode] => 33188
[nlink] => 1
[uid] => 0
[gid] => 0
[rdev] => 0
[size] => 1114
[atime] => 1061067181
[mtime] => 1056136526
[ctime] => 1056136526
[blksize] => 4096
[blocks] => 8
)
函数,除了它在打开文件指针而不是文件名上操作。
{{1}}
输出:
{{1}}
答案 1 :(得分:0)
尝试这样..
<?php
if ($handle = opendir('./uploaded')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo '<div class="col-md-3"><div class="panel panel-default"><!-- Default panel contents --><div class="panel-heading">'.$entry.'</div><div class="panel-body">'.$entry.'</div><div class="panel-footer"><a href="./uploaded/'.$entry.'">View File</a></div></div></div>';
echo $entry . ': ' . filesize($entry) . ' bytes'; // Gets file size e.g. xyz.txt: 1024 bytes
}
}
closedir($handle);
}
?>