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
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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

SOrry for the double post. But i need help man.

 

Ok rarebit your works.

But i think you have misslead what i meant.

 

What i need is. Yes to list the directory.

But i need to be able to go to that directory too.

To play the music.

 

Thanks.

Regards,

Otoom

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.