开发者

Why is this Recursive Iterator for file sizes in php not correct?

I'm am trying to get file names, sizes and permissions in php using RecursiveIteratorIterator and RecursiveDirectoryIterator .

The code below works for outputting all files and directory names and sizes correctly, but the permissions are wrong ( using get $file->getPerms).

In this case all permissions being output are the same, 0666 which I suspect is the first file only.

Also note that if I do not use foreach(new RecursiveIteratorIterator($it) as $file) and instead just use foreach($it as $file) it works correctly, but it is not recursive ( aka it shows no sub-directories/files).

//remove some file types I don't want showing
$filetypes = array("jpg", "png", "css", "gif");


$it = new RecursiveDirectoryIterator("/root-director开发者_运维百科y");

foreach(new RecursiveIteratorIterator($it) as $file) {


      //foreach($it as $file) {
      // ^^This works but it's not recursive ?!

 //remove files in $filetypes array
 $filetype = pathinfo($file, PATHINFO_EXTENSION); 

 if (!in_array(strtolower($filetype), $filetypes)) {

//outputs file name correct
echo $file ;

//outputs wrong permissions      
echo substr(sprintf('%o', $file->getPerms()), -4);

//outputs file size correct
echo number_format($file->getSize()/1024, 2) . " KB"; 

 }
}


Simply put this does not seem to return accurate results on a Wamp stack, possibly a bug.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜