Ok altering the small example of code that was shown... and it works... kinda lol... This is the code and after this code ill show you the results and why its not working right.
<?php
require("dbconn.php");
$color1 = "#999999";
$color2 = "#FFFFFF";
$row_count = 0;
*/ I take the directory and run it through the loop to give me the folders in it.
$d = dir("./music/");
while(false !== ($e = $d->read())) {
*/ the echo shows me it does read off the three different folders correctly.
echo $e . '<br/>';
/
I replace the folders with the varible $e, WHICH should run through the loop and put a new folder each loop showing me the .mp3 there.
/
foreach(glob("./music/$e/*.mp3") as $filename)
{
$filename = substr($filename, 0, strlen("./music/$e/")); [/B]
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<tr>
<td width=\"286\" bgcolor=\"$row_color\"><div align=\"left\" class=\"gypsybody\">
<div align=\"center\"><a href=\"$filename\" target=\"_blank\">$filename</a></div>
</div></td>
<td width=\"110\" bgcolor=\"$row_color\"><div align=\"left\" class=\"gypsybody\">
<div align=\"center\">". filesize($filename) ."</div>
</div></td>
</tr>
<br />\n";
$row_count++;
} }
?>
This was the result of the prior code....
Song Title File Size
./music/Chicago/ 4096
./music/../ 12288
./music/../ 12288
As you see it does not capture the .mp3 like it should and instead gives just a directory and still doesnt even go through each city(folder).
On the second code... which is this way....
<?php
function trimmer( $a )
{
$arr = array( '.mp3', '.', '_', '[', ']', '-' );
return( ucwords( str_replace( $arr, " ", $a ) ) );
}
function f( $kvtnev )
{
$kvt = opendir( $kvtnev );
while ( gettype( $fajl = readdir( $kvt ) ) !== "boolean" ) {
/* if this is a folder*/
if ( is_dir( "$kvtnev/$fajl" ) AND $fajl != '.' AND $fajl != '..' ) {
print "<br />(D)";
print trimmer( "$fajl<br>" );
/*lets call this lister function on this folder*/
f( "$kvtnev/$fajl" );
}
/* if this is a file*/
if ( is_file( "$kvtnev/$fajl" ) AND strstr( $fajl, ".mp3" ) ) {
$url = htmlentities( "$kvtnev/$fajl" );
print "(F)";
// print "==== $fajl<br>";
print "[<a href=\"$url\">" . trimmer( $fajl ) . "</a>]<br />\r";
}
}
closedir( $kvt );
}
f( "music" );
?>
The output for this coding was as follows...
(D)Houston
(D)Chicago
(F)[Open The Eyes Of My Heart 03 Third Day & Caedmon's Call God Of Wonders ]
(D)Dallas
As you see it works kinda... it pulled up each folder but didnt list it in any particular order and the only music it found again was in chicago even though, i have music in each folder.
Finally the third coding which i placed on the site does no output but cuts off the rest of the page because of something not working right. I have been through it but cant find out what is wrong with the coding... it is this...
<?php
function trimmer( $a )
{
$arr = array( '.mp3', '.', '_', '[', ']', '-' );
return( ucwords( str_replace( $arr, " ", $a ) ) );
}
function f( $kvtnev )
{
$d = dir("$kvtnev");
while(false !== ($e = $d->read()))
{
if($e=="." OR $e=="..")
continue;
echo trimmer($e) . '<br/>';
files("$kvtnev/$e/");
}
}
function files($a){
$color1 = "#999999";
$color2 = "#FFFFFF";
$row_count = 0;
foreach (glob($a."*.mp3") as $filename) {
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<tr>
<td width=\"286\" bgcolor=\"$row_color\"><div align=\"left\" class=\"gypsybody\">
<div align=\"center\"><a href=\"{$filename}\" target=\"_blank\">". trimmer ($filename) ."</a></div>
</div></td>
<td width=\"110\" bgcolor=\"$row_color\"><div align=\"left\" class=\"gypsybody\">
<div align=\"center\">". filesize($filename) ."</div>
</div></td>
</tr>
<br />\n";
$row_count++;
}
}
f("music");
?>
So here is what I want ultimately... I want where someone can upload music via FTP and under the music directory they would place a NEW FOLDER for each city the music is coming from, such as Houston. Upload the music to the directory ./music/houston/ as the example.
Then on the webpage the PHP will read in the directory of music what folders are there (which are cities) echo a new header for the table called the folder name (ex. HOUSTON) then under that have a cell say Music Title and File Size. Then list the particular music titles and file sizes pertaining to that folder (city). When all music for that folder (city) is done then it goes to the new folder (city) located in music directory and repeats the command.
This will give a nice way for people to see the music that has been upload for download and seperated by city of orgin. Is this possible with the coding we have here? I believe it is but for some reason I am getting snagged by my misunderstanding of the coding or just the code is not functioning the way i would like it.
I hope this explains it best... And again thank you guys for helping me... It will be so much better for me then having to update the actual page weekly with new music....