Jump to content

[SOLVED] Auto Music File Adding.


Otoom

Recommended Posts

Ok well im new.

Sort of new to php too.

 

I am currently making a Music website. I would like a php script. That when i add music to the directory / folder. It will automaticly be added onto the website. I know this will be hard. But would love it if someone can help me out with it. Or maybe code something small up.

 

 

Any ideas?

 

Regards,

Otoom

Link to comment
https://forums.phpfreaks.com/topic/80760-solved-auto-music-file-adding/
Share on other sites

this just extracted from something, so it'll get you going (but you'll have to play around with it!):

$dirs=opendir($base);
	while (($e=readdir($dirs))!==false)
	{
		if( (strcmp($e, '.') == 0) || (strcmp($e, "..") == 0) )
		{
			continue;
		}
		elseif(is_dir($base.$e))
		{
			print "dir: ".$base.$e."<br>";
		}
		else
		{
			print "file: ".$base.$e."<br>";
		}
	}

and $base is the directory your looking at. to do a whole directory tree you'll want to use it recursively...

I found this one:

 

<?php

// open this directory 
$myDirectory = opendir("music");

// get each entry
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}

// close directory
closedir($myDirectory);

//	count elements in array
$indexCount	= count($dirArray);
Print ("$indexCount files<br>\n");

// sort them
sort($dirArray);

// print them
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");

print("<TR><TH>Filename</TH></TR>\n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
        if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
	print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
	print("</TR>\n");
}
}
print("</TABLE>\n");

 

But one problem. It find everything perfectly.

The directory. As im trying on Wamp first.

Is

 

Musix/music <= Thats where the music is stored. So i put the $dir as music.

But when i try and open it. It seems to think that the files are in the main directory and wont open the music directory where the files actually are.

 

Regards,

Otoom

Try:

 

<?php
$base="music/";
$dirs=opendir($base);
	while (($e=readdir($dirs))!==false)
	{
		if( (strcmp($e, '.') == 0) || (strcmp($e, "..") == 0) )
		{
			continue;
		}
		elseif(is_dir($base.$e))
		{
			print "dir: ".$base.$e."<br>";
		}
		else
		{
			print "file: <a href='".$base.$e."'>".$base.$e."</a><br>";
		}
	}
?> 

 

Simple matter of adding a correct hyperlink.

Yep. That works.

I tryed it before. But didnt want to triple post.

Thanks for all your help guys.

 

Also. Instead of making a new topics about this. Unless you guys want me to. Slit it. But.

 

I now need to make a upload form. That has a brouse button so they can upload a song. Then when they click upload it gets saved into the directory. I will also google this.

 

Regards,

Otoom

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.