Jump to content

help with some code- cant work it out...


map200uk

Recommended Posts

Hi, sorry to post this, but i cannot work out my problem with my code

 

i am trying to write the results to an array each time a match is found

 

<?php
         $mp3[]=array();
 $x=0;
 function scandir1($dir)
        
{

echo "the value of x is $x";
 $dirlist = opendir($dir); // open the directory
      while ($file = readdir ($dirlist)) // while file = readdir 
            {
                if ($file != '.' && $file != '..') //if file = . current dir or .. back 2 dirs
                {
      $newpath = $dir.'/'.$file; 
	  $level = explode('/',$newpath); //split newpath into array so /home/mark becomes array[0]=>home array[1=>mark
	  if (is_dir($newpath))
             {
		       echo "\nDirectory found at \n  + $newpath";
		       
                       

                      $content=scandir1($newpath);

                    }else{
		//if newpath is not dir
                  echo "\nno dir";
	  $filen=end($level);
	  if(ereg("mp3$",$filen))
	  {
	  	$x=$x+1;
		echo "The value of x is $x";
		echo "we found mp3, $filen @ $newpath";
		$mp3[]=$filen;
	}
	  echo "**** $filen"
	  ;
                   }

                }

            }

             closedir($dirlist);
		echo "\nCHECK";
	return $mp3;
         
   

        }

        echo '<pre>';

        print_r(scandir1('.'));

         echo '</pre>';

?> 

all i want to do is if a file ending mp3 is found add the file to the mp3 array

however each time the array only contains 1 entry

 

 

 

  if(ereg("mp3$",$filen))

  {

  $x=$x+1;

echo "The value of x is $x";

echo "we found mp3, $filen @ $newpath";

$mp3[]=$filen;

}

 

thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/47635-help-with-some-code-cant-work-it-out/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.