Jump to content


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


Getting files from a directory based on a mysql query....

Recommended Posts

Hi all,

I am new to this forum and hopefully the person who referred me here is a reliable source in stating "somone will be able to help you no doubt, there are some excellent coders that use it".
Here we go then.....
I am making a playlist for my website, what i want it to do is read from the database table a list of songs that a certain user may of uploaded. At present i can get the script to read from the directory but there is no definition as to what songs are played. E.g. all songs are played to all users. I want the songs for each user inserted into the playlist.
here's the code:

# Script 13.1 - header.html
// This page begins the HTML header for the site.

// Start output buffering.
// Initialize a session.

$ti = $_SESSION['first_name'];

include "../includes/mysql_connect.php";

$sql = "SELECT file_name from uploads where user_id = blah@blah.blah";
$query = mysql_query($sql) or mysql_error();
$moo = $rowsee['imgstatus'];

$playlist[]= "mp3/".$moo;

// setting the directory to search for mp3 files
//$dir = "mp3/".$moo;

// reading the directory and inserting the mp3 files in the playlist array
//$playlist = array();
//$fdir = opendir($dir);
//while($i = readdir($fdir)) {

   // if a .mp3 string is found, add the file to the array
   //if (strpos(strtolower($i),".mp3") !== false)
    // $playlist[] = $i.$moo;
// close the directory

sort($playlist);// make an alphabetical ordered list (if you don't want an ordered list, just comment this line)
shuffle($playlist);// make a randomized list (if you don't want a randomized list, just comment this line)

header("Content-type: text/xml");
// echoing the playlist to flash
echo "<player showDisplay=\"yes\" showPlaylist=\"yes\" autoStart=\"yes\">\n";
for ($i=0; $i<sizeof($playlist); $i++) {
   // for the title it filters the directory and the .mp3 extension out
   $title = str_replace(".mp3","",$playlist[$i]);
   // clean filename (convert "_" into " ")
   $title = str_replace("_", " ", $title);
   echo "  <song path=\"$dir{$playlist[$i]}\" title=\"$title\" />";
   echo "$moo";
echo "</player>";


this has been driving me mad for over a week now, sleepless nights are a result!!

Anyone who can help it would be much much appreciated.


Share this post

Link to post
Share on other sites


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.