Re: Creating/printing array issues

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

 



By the way, I was getting a PHP error with an unexpected ")" on line 47
($aryPhotos), so I added the two \\ before {survey*_.php and now the page
won't load, won't even display a PHP error.



On Tue, Jul 28, 2009 at 11:06 AM, Allen McCabe <allenmccabe@xxxxxxxxx>wrote:

> 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);
> $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);
> //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