Need a small recursive file search script in PHP

777php

Diamond Member
Jul 17, 2001
3,498
0
0
I have some deeply nested include files which I need included on some top level pages ie:

/direct/path/to/index.php <---where include is called
/location/of/include.inc

another example
../../../../../index.php
../../include.inc

I need for a script to be run on index.php lookinf recursively folder by folder downwards to find the inlcude.inc. Once the file is found I need for the script to then include the file within the parent.

I have tried a few methods but I can't seem to find one that works efficiently. Thanks guys.
 

777php

Diamond Member
Jul 17, 2001
3,498
0
0
I don't think so....I'm gonna do a php.net search

In the meantime
I've tried this but it didn't work


$fileName = ("botlnav.inc");
function myInclude($fileName)
{
$rootPath = getcwd()."/";

$aryFilePath = split("/", $fileName);
$fileToInclude = array_pop($aryFilePath);
$includePath = join("/", $aryFilePath) . "/";

chdir($rootPath.$includePath);
include($fileToInclude);
chdir($rootPath);
}
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
You can't do system calls from in PHP?

Someone please remind me why PHP is soooo much better than CGI w/ Perl?
 

777php

Diamond Member
Jul 17, 2001
3,498
0
0
It seems you can do a system call

php.net

I tried your code notfred but I'm guessing i got the sytax incorrect.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Well, it's jsut the unix find command that I've stuck inside the system call there. You'll have to write the command to suit your applciation. Mine looks in /path/ for a file called "file_I_want"... it was jsut an example.
 

777php

Diamond Member
Jul 17, 2001
3,498
0
0
oh i know that....i meant i followed your example, not exactly and added php tags/functions.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
ah, ok. Yeah, I'm sure you'll need a few more lines than jsut the system call, but it's a lot easier to use a tool that's already there than to write a recursive search script.