PHP MP3 Script Error Help!

Hi I found this script and it works great however when i try it in AOL
It acts very strangly what hapens is when you go to download a file it works once and then when you try agin to try and download another file directly after the first one all you get is a page of code this however doesnot happen in IE so my question to anyone is can we modifiy this script to be error free in AOL as well and does any one know what whould couse the script to output garbage code instead of downloading the selected file in AOL and why does it work only the first time but not the second I hope somone out there can duplicate my problem and come up with a solution I should mentin I used AOL 8.0 for the test

So if any one can take the code and test it and try and recreate what happens here and has a fix that would be so greatly appreciated

<?php

////////Configuration\\\\\\\\\

//Make sure there is a trailing slash
//Make sure the music directory contains a directory with the artists name
//in this directory you should place the artists mp3 files
$artist_path='/home/whatever/public_html/mp3/music/'; //Path to Artist Folders

//Make sure there is NOT a trailing slash
//Leave as is if your script resides in your main directory
$url_to_script='http://www.yoururl.com'; //URL To the music.php script

/* INSTRUCTIONS

Modify the two variables above called $artist_path and $url_to_script.

After that thats all you have to do unless your

music structure is not correct for this script to work.

The Structure should be as follows

>>mp3s folder

>>this script

>>artist folders

>>artists tracks

So for example:

/home/user/public_html/music/

/home/user/public_html/music/music.php

/home/user/public_html/music/mp3s/The Beatles

/home/user/publc_html/music/mp3s/The Beatles/Yellow Submarine.mp3

MAKE SURE YOU NAME THIS SCRIPT MUSIC.PHP!!!!!

*/

function GetDirArray($sPath)

{

//Load Directory Into Array

$handle=opendir($sPath);

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

if ($file == '.' || $file == '..') { $file = ''; }

else {$retVal[count($retVal)] = $file; }

}

//Clean up and sort

closedir($handle);

sort($retVal);

return $retVal;

}

$Artists = GetDirArray($artist_path);

$Track_dir = $artist_path.$Artists[$artistnumber]."/";

$Tracks = GetDirArray($Track_dir);

if (($TrackSubmit) && ($action=='download')) {

$Track=$Tracks[$tracknumber];

$Track=stripslashes($Track);

$Track=ereg_replace("%20"," ",$Track);

$name=$Track;

$Artist_use = $Artists[$artistnumber];

$Track = $artist_path.$Artist_use."/".$Track;

$open= fopen ($Track, "r");

$data = fread ($open, filesize ($Track));

header("Content-type: audio/mpeg");

header("Content-length: $size");

header("Content-Disposition: attachment; filename=$name");

header("Content-Description: PHP Generated Data");

echo $data;

fclose ($track);

}

if ($action=='') {

echo "";

for($i = 0; $i < count($Artists); $i++) {

if ($i == $artistnumber) {

echo "$Artists[$i]";

}else {

echo "$Artists[$i]";

}}

echo "";

}

if ($SubmitArtist) {

// use target='_blank' if you want to pop a blank page behind the download window
//Example action='$url_to_script/media.php'target='_blank'

echo "";

for($i = 0; $i < count($Tracks); $i++) {

$full_path = $Track_dir;

$full_path .= '/';

$full_path .= $Tracks[$i];

$size =filesize($full_path);

if ($size >= 1073741824) {

$size = round($size / 1073741824 * 100) / 100 .

" gb";

} elseif ($size >= 1048576) {

$size = round($size / 1048576 * 100) / 100 .

" mb";

} elseif ($size >= 1024) {

$size = round($size / 1024 * 100) / 100 .

" kb";

} else {

$size = $size . "b";

}

echo "$Tracks[$i] - ( $size )";

}

echo "";

}

?>

By Anonymous on

Stalk me!

Drupal Association Member