Question
I'm having problems with the glob:// stream wrapper included in the PHP 5.3.0 version. I'm using the following PHP version:
PHP 5.3.1-0.dotdeb.1 with Suhosin-Patch (cli) (built: Dec 5 2009 20:08:29) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
When I try to execute the following example from the PHP.net website:
<?php
// Loop over all *.php files in ext/spl/examples/ directory
// and print the filename and its size
$it = new DirectoryIterator("glob://*.php");
foreach($it as $f) {
printf("%s: %.1FK\n", $f->getFilename(), $f->getSize()/1024);
}
?>
Note that I remove the folder from the original example and left only the php extension
I get a PHP error with the following message:
SplFileInfo::getSize(): stat failed for [first php file name].php
While searching at Google about this error I discover that someone had the same problem one year ago, but looks like they fixed it.
So... My question is: Anyone is using glob:// wrapper? Am I doing something wrong? Anyone with the same problem?
Note: I already know I can do the same in other different ways but I want to test the glob:// stream wrapper :)
Solution 2
I sent this bug to PHP Bugs they confirm it's a current PHP 5.3.1 bug.
They are trying to fix it; see Bug report #51068.
Thank you all for your answers :)
OTHER TIPS
The error message is pretty clear. It's looking for "/00.php" (note the slash) in the root directory. I guess you need getPathName here (http://www.php.net/manual/en/directoryiterator.getpathname.php) not getFileName
I discover the problem: glob:// looks like is only accepting full paths or relative paths but not current path.
For example, to retrive the current path I need to use:
$it = new DirectoryIterator("glob:///home/pedro/public_html/*");
foreach($it as $f) {
printf("%s: %.1FK<br />", $f->getFilename(), $f->getSize()/1024);
}
But I cannot use the glob://* query for get all the current folder files and folders.
However I can make subfolders search using relative paths:
$it = new DirectoryIterator("glob://subfolder/*");
foreach($it as $f) {
printf("%s: %.1FK<br />", $f->getFilename(), $f->getSize()/1024);
}
I hope this helps anyone trying to make something with this new wrapper.