tags:

views:

239

answers:

3

Hi all,

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 :)

+2  A: 

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

stereofrog
Then it should give me all the php files in the root path and not the current folder files, isn't it?
Pedro Laguna
@Pedro, it's probably checking the root path *of your server*. There wouldn't be any files there. Try `new DirectoryIterator("glob:/".dirname(__FILE__)."/*.php");`
Josh
A: 

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.

Pedro Laguna
Did you try `new DirectoryIterator("glob://./*");` ?
Sekhat
A: 

Ok, I don't know what is the right way to do this in Stack Overflow but after sending this bug to the PHP Bugs they decide it's a current PHP 5.3.1 bug and they are trying to fix it: http://bugs.php.net/bug.php?id=51068

Thank you all for your answers :)

Pedro Laguna