Thursday, September 10, 2009

PHP directory listing : convert a folder tree into an array

Hi there!

in a post few months ago i talked about Directory listing in php, there i show a pair of function to list a directory and turn it into an array.

Well today i come back to that function and change it a little to get it better.

It's quite simple, it start from a path (btw thinking correct) and push it into a structured array. In wich every array element mean a subdirectory, and a null value mean a file.

You can choose the recursive mode in which, when a subfolder is found goes deep into it (recursively too) to fill the array with file and subfolder of that directory.

It's simple, it just check the params $recurrent for true and that the "entry" scaned by read method from metaclass dir is a directory.

Hope someone could find it useful.


function array_converter($path, $recurrent = false, $tree = array())
{
$path = realpath($path);
$d = dir($path);
while(false != ($entry = $d->read()))
{
$complete = $d->path."/".$entry;
if(is_dir($complete) && $entry !== '.' && $entry !== '..')
{
$tree[$entry] = array();
if($recurrent && $entry !== '.' && $entry !== '..')
{
$tree[$entry] = array_converter($complete, $recurrent, $tree[$path][$entry]);
}
} elseif($entry !== '.' && $entry !== '..') {
$tree[$entry] = null;
}
}
$d->close();
return $tree;
}

Wednesday, September 9, 2009

Silence please, one minute: Mike Bongiorno

Too much to say,

you are great, the most! You change our point of view, you win on TV.

Thanks Mike, so much.

Allegria!

Tuesday, September 1, 2009

PHP RESTful WebService

Lately im working on a restful php webservice.
In its concepts RESTful is quite easy, but it is still not really understand by most of web programmers.

So if you are interested, first of all you should start to study what behind REST, so its architecture. Good resources are of course wikipedia and Roy Thomas Fielding's dissertation which start the most of works.

Then you may try to develop, or study already coded RESTful web service, the most comes from ruby and python programming languages. Im quite sure to be blind, but in the end i really didn't find goods PHP resources about RESTful (genuine RESTful i mean!) from surfing the web.

The really best i found is an article signed by Gareth Jones: Building a RESTful Web application with PHP and it's starting point lornajane.

A really good book (which i found such likes a REST bible) is RESTful Web Service, written by Leonard Richardson and Sam Ruby.

I know it's a lot of things, this is the RESTful price to pay!

But it's good, trust me people!