Otoom Posted December 8, 2007 Share Posted December 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/80760-solved-auto-music-file-adding/ Share on other sites More sharing options...
LemonInflux Posted December 8, 2007 Share Posted December 8, 2007 http://www.php.net/mkdir for making folders look for an uploading tutorial for adding music Quote Link to comment https://forums.phpfreaks.com/topic/80760-solved-auto-music-file-adding/#findComment-409642 Share on other sites More sharing options...
rarebit Posted December 8, 2007 Share Posted December 8, 2007 a simple way is that all uploaded music files are put in a directory(s) and there is a php file somewhere that when called list's the contents of said directories Quote Link to comment https://forums.phpfreaks.com/topic/80760-solved-auto-music-file-adding/#findComment-409644 Share on other sites More sharing options...
Otoom Posted December 8, 2007 Author Share Posted December 8, 2007 @ rarebit. I kno. Like when you just upload things. Without an index. It lists it. Like that? But i dont know how to do that in a index. Thanks. Regards, Otoom Quote Link to comment https://forums.phpfreaks.com/topic/80760-solved-auto-music-file-adding/#findComment-409648 Share on other sites More sharing options...
rarebit Posted December 8, 2007 Share Posted December 8, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/80760-solved-auto-music-file-adding/#findComment-409652 Share on other sites More sharing options...
Otoom Posted December 8, 2007 Author Share Posted December 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/80760-solved-auto-music-file-adding/#findComment-409658 Share on other sites More sharing options...
Otoom Posted December 8, 2007 Author Share Posted December 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/80760-solved-auto-music-file-adding/#findComment-409670 Share on other sites More sharing options...
jacksonmj Posted December 8, 2007 Share Posted December 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/80760-solved-auto-music-file-adding/#findComment-409680 Share on other sites More sharing options...
Otoom Posted December 8, 2007 Author Share Posted December 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/80760-solved-auto-music-file-adding/#findComment-409684 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.