Creating/printing array issues

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I found a php script to find all file types with a file-name formula and put
them into an array. I then wanted to echo this array (possibly with links to
the files).

I want my default page to look for and list all php files with
"survey_*.php", the asterisk being any number, so the results should be:
survey_01.php, survey_02.php, etc.

Here is my code:

<?php
/**
* Recursive version of glob
*
* @return array containing all pattern-matched files.
*
* @param string $sDir      Directory to start with.
* @param string $sPattern  Pattern to glob for.
* @param int $nFlags       Flags sent to glob.
*/
function rglob($sDir, $sPattern, $nFlags = NULL)
{
 $sDir = escapeshellcmd($sDir);
 // Get the list of all matching files currently in the
 // directory.
 $aFiles = glob("$sDir/$sPattern", $nFlags);
 // Then get a list of all directories in this directory, and
 // run ourselves on the resulting array.  This is the
 // recursion step, which will not execute if there are no
 // directories.
 foreach (glob("$sDir/*", GLOB_ONLYDIR) as $sSubDir)
 {
  $aSubFiles = rglob($sSubDir, $sPattern, $nFlags);
  $aFiles = array_merge($aFiles, $aSubFiles);
 }
 // The array we return contains the files we found, and the
 // files all of our children found.
 return $aFiles;
}
$aryPhotos = rglob("./surveys","\\{survey_*.php}",GLOB_BRACE<file://%7bsurvey_*.php%7d%22,glob_brace/>
);
$aryExt = array("php");
$propid = $_REQUEST['mlsid']; // I assume the id will be in the querystring
// get the proper match pattern according to our Extension criteria
foreach ($aryExt as $e) {
 $aryPattern[] = $propid."_*.$e";
}
$pattern = join(",", $aryPattern); // comma separated list
// Get the filenames
$aryPhotos = rglob("./surveys","\\{$pattern}",GLOB_BRACE<file://%7b$pattern%7d%22,glob_brace/>);

//print out our array
print_r($aryPhotos);


?>


Also, it would be nice to have an if/else statement to say there are no
"surveys" (survey_*.php files) available if there are none in the /surveys
directory.

Any and all help would be greatly appreciated!

-Allen McCabe

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux