File Paths Into Variables (2)

From: Date: Tue, 17 Oct 2000 04:33:58 +0000
Subject: File Paths Into Variables (2)
Groups: php.db 
Request: Send a blank email to php-db+get-3664@lists.php.net to get a copy of this message
I mentioned earlier the script I was developing. Would this work? Is there any way to make this work easier? This script goes through a directory, adding a lyrics file, and information about the lyrics ex. l/led_zeppelin/stairway_to_heaven.txt would insert the letter, artist, song, and actuall BLOB field <?php // call the loadtabs function as follows: //$toppatharray = array("/dtabs"); //loadtabs($toppatharray); // loadtabs function // // it expects to be passed an array containing elements of a path // e.g. [0] = /dtabs [1] = /l [2] = /led_zepplin etc. // function loadtabs($cumpatharray) { // construct a string out of the array // there may be a built-in function to do this // but I haven't found one $dirpath = ""; $num_elements = count($cumpatharray); for ($idx = 0; $idx < $num_elements; $idx++;) { $dirpath = $dirpath + $cumpatharray[$idx]; } // switch to the directory (I'm not sure if this is needed) echo ("chdir to " + $dirpath); chdir($dirpath); // construct a dir object for the current directory. Perhaps // the above line and this one could be combined into a // single $dir = dir($dirpath); which would mean we wouldn't // have to pop up a directory level later on $dir = dir("."); // Make sure we're at the beginning (may not be needed) $dir->rewind(); while ($file = $dir->read()) { // we've got an element in this directory if (is_dir($file)) { // we've got a directory! // I'm assuming that we don't have . or .. here $newfile = "/" + $file; // we don't want to muck the array that was passed in // to us since we're still in the while loop and may // need it later $newarray = $cumpatharray; // Add the directory on to the end of the array $newarray[] = $newfile; // recurse loadtabs( $newarray); } else { // We've got something other than a directory echo( split("/",$cumpatharray) + " :" + $file; // SQL insert goes here after we change underscores // to nospace // SQLSOMETHING } } } ?>

« previous php.db (#3664) next »