Jump to content


Photo

can anyone help me edit this php to make it search sub folders aswell


  • Please log in to reply
23 replies to this topic

#21 madspof

madspof
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 30 August 2006 - 09:53 PM

yer that works but it some how has bypassed the whole point of this all as it will not list sub directories and i already have a script that can do what we have jsut done see:
<?php



$directory = "music"; 

$fp = opendir($directory);

while ($file = readdir($fp)) {

    if (!ereg("^\.", $file)) {
   
        $file_url = "$directory/" . $file;
?>


<body bgproperties="fixed" background="back%20(Custom).jpg">
<div align="center"><a href="<?php echo("playertest.php?song=$file"); ?>" target="banner2"><?php echo($file); ?></a><br>
 
  <?php
    }
}
closedir($fp);

?>
</div>


#22 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 30 August 2006 - 09:59 PM

I am sorry, but I have to quit!

I sent you code that was perfectly allright. It displayed all the subdirectories and all files therein.
You changed that code. And suddenly it does not function any more as intended. You can't blame me for that. So, as I said: I quit.

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#23 madspof

madspof
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 30 August 2006 - 10:13 PM

bare with am sry but am trying to get my head round all this and i rly wnt to try and get this to work now i entered the last correction you sent me but it is missing out hte sub directories plz can anyone help

#24 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 30 August 2006 - 11:01 PM

Now for the last time then. But I must caution you: this scripts works, but I have not sorted the directories. For the time being: if you make sure that the music directory contains no files, just sub-directories, you are fine. Here is the code:
<?php 
getDirectory('./music');

// SAMPLES:
//   getDirectory( "." ); 
// Get the current directory 
//   getDirectory( "./files/includes" ); 
// Get contents of the "files/includes" folder   */

function getDirectory( $path = '.', $level = 0 ){ 
    $ignore = array( 'cgi-bin', '.', '..' ); 
    // Directories to ignore when listing output. Many hosts 
    // will deny PHP access to the cgi-bin. 
    $dh = @opendir( $path ); 
    // Open the directory to the handle $dh 
     
    while( false !== ( $file = readdir( $dh ) ) ){ 
    // Loop through the directory 
        if( !in_array( $file, $ignore ) ){ 
        // Check that this file is not to be ignored 
            $spaces = str_repeat( '&nbsp;', ( $level * 4 ) );
            // Just to add spacing to the list, to better 
            // show the directory tree.
            if( is_dir( "$path/$file" ) ){ 
            // Its a directory, so we need to keep reading down... 
	
                echo "<strong>$spaces"."Directory: $file</strong><br />";
                getDirectory( "$path/$file", ($level+1) ); 
                // Re-call this same function but on a new directory. 
                // this is what makes function recursive. 
            } else { 
                echo "$spaces<a href=playertest.php?song=".str_replace(" ", "%20", $file)." target=main>$file</a><br />";
                // Just print out the filename 
            } 
        } 
    } 
    closedir( $dh ); 
    // Close the directory handle 
} 
?>

Good luck with it. And don't forget NOT to put any normal files in the start directory, just sub-directories with all your mp3 files.

Ronald  8) 8)
RTFM is an almost extinct art form, it should be subsidized.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users