Jump to content

Display mp3 script


Ojay

Recommended Posts

Hey everyone... this is my first post, WOOOOO! It's good to be here!

 

I am here because my basic knowledge of PHP is restricting me... All i want to create is a script that displays a directory of mp3's as dynamically generated links. I can build a form to upload the mp3's to a directory, i just can't find/figure out a script that will display them.

 

If any one knows a tutorial, script or is willing to show me how to achieve such a thing i will drink a beer and toast it in honour of their name.

 

thanks for any help!

 

xxx

Link to comment
https://forums.phpfreaks.com/topic/41359-display-mp3-script/
Share on other sites

One way to do what you are talking about is store a file link to the mp3 in a mysql database.  Then you query the database and display the rows returned on your site as links.  This is fairly simple and is something I have done in the past.

 

The other option, which I have NOT done, is to use some of the directory functions.  In particular you'd be interested in the scandir() function.  Check out the manual here: http://us2.php.net/dir.  I'm guessing the scandir function returns an array of all files in a given directory and then you can use a foreach loop to iterate through them.  This is probably the easiest of the two solutions, but I'm not sure which is the best.

Link to comment
https://forums.phpfreaks.com/topic/41359-display-mp3-script/#findComment-200396
Share on other sites

Not to hijack your thread, but if any more experience PHP programmers read this which solution do you think I provided is the "better" of the two (or other solutions as well).  Basically I'm asking: Does a query / echo the returned rows from a db, result in faster response time and less load on the server, than the scandir() method?  Please advise.

Link to comment
https://forums.phpfreaks.com/topic/41359-display-mp3-script/#findComment-200399
Share on other sites

here is some code I use to dynamically show all files in a directory (I did not write this, and don't remember where I got it). You should be able to modify it to show only .mp3 files pretty easy.

 

<?php

 

$cwd=getcwd();

 

$path = "$cwd";

 

$dir_handle = @opendir($path) or die("Unable to open $path");

 

 

while ($file = readdir($dir_handle))

{

  if($file!="." && $file!=".." && $file !="index.php")

      echo "<li><a href='$file'>$file</a></li>";

 

}

//closing the directory

closedir($dir_handle);

?>

Link to comment
https://forums.phpfreaks.com/topic/41359-display-mp3-script/#findComment-200432
Share on other sites

here is a script i have for a fileing service, it links to all the files in a specific folder.. i dunno how much of the code is good for you, but there is alot of good stuff in here...

 

if(isset($_POST['submit2'])){

$first=$_POST['new'];
$end=$_POST['end'];
$name="$first.$end";
$types = array('gif', 'jpeg', 'jpg', 'pjpeg','bmp','txt','doc','php','html','mpg','css','mpeg','png','xls');
$parts = explode('.', $name);
$key = count($parts) - 1;
$ext = strtolower($parts[$key]);
if (in_array($ext, $types)) {
$page = fopen("userfolders/$folder/$name", 'x+');
$content=" ";
fwrite($page, $content);
$cpage="INSERT INTO files VALUES('','$name','$end','$user','0')";
$result = mysql_query($cpage) or die ("Error in query: $cpage. ".mysql_error()); 
}else{
echo "Sorry Your File is not supported, Please The administrator";
}


if(isset($_POST['upload'])){
$dest="userfolders/$folder/".$_FILES['ph']['name'];

copy($_FILES['ph']['tmp_name'],"$dest");
$filer=$_FILES['ph']['name'];
$type=$_FILES['ph']['type'];
$cpage="INSERT INTO files VALUES('','$filer','$type','$user','0')";
$result = mysql_query($cpage) or die ("Error in query: $cpage. ".mysql_error()); 
       print "File has been successfully uploaded!<br>";
}
}
$dir = "userfolders/$folder/";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}



$delete = array();
echo "<table align=center cellspacing=0 cellpadding=5>";
$bg = '#eeeeee';
echo "<tr><td>File</td><td>Download</td><td>Delete</td><td>Public</td></tr><form method=POST>";
$re = array_search('..', $files);
$rem = array_search('.', $files);
unset($files[$rem], $files[$re]);
$totalp = count($files);
foreach($files as $id => $file){
$file1 = str_replace(" ", "_", "$file");
$file2 = str_replace(".", ".", "$file1");
$nfile = base64_encode("$file1");
echo '<tr>';
echo "<td align=left><a href=page.php?f=$nfile>$file2</a></td><td><a href=download.php?f=$nfile><b><font color=black>Download</font></b></a></td><td><input type=checkbox name=delete[] value=$file></td><td><a href=public.php?f=$nfile>Make Public</a></td></tr>";
echo '</tr>';
}
echo "<tr><td>Total Files: $totalp</td><td></td><td><input type=submit name=subm value=Delete></td></tr></table></form>";

if(isset($_POST['subm'])){
$delete=$_POST['delete'];

foreach($delete as $rfiles){
@unlink("userfolders/$folder/$rfiles") or die ("The file doesnt exist!");
$rem="DELETE FROM files WHERE Name='$rfiles'";
$result = mysql_query($rem) or die ("Error in query: $rem. ".mysql_error()); 
}
}
}

Link to comment
https://forums.phpfreaks.com/topic/41359-display-mp3-script/#findComment-200463
Share on other sites

Archived

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

×
×
  • Create New...

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.