willsradio Posted May 31, 2006 Share Posted May 31, 2006 Just wanna say thanks for reading this post. I was wondering if it there was a way to create a php program that would read all the files in a directory on my webspace and then give me link to each song outputted on a TXT file then out put again on an HTML file. I don't know if I am being clear but i mean like this: You put Song.mp3 into directory /music/ on your web host. Well I want a PHP page that will read that directory and that will give each song an ID number, from first to last, and then give the link kinda like this: ID Link 1 ...../music/Song.mp3 If any one knows a link to where I could read how to do this or something similar, I have very basic knowledge in PHP but I learn fast. Thanks in advance for any help. Link to comment Share on other sites More sharing options...
facugaich Posted May 31, 2006 Share Posted May 31, 2006 (edited) Here's something I managed to do from another script I had done before. It doesn't include the txt because I did it in a hurry. Also, it works only with 3 letter extensions, although that can be fixed. Hope it helps. <?php/* Files' Vars */$id = 0;$dir = "music";$file_types = array(".mp3", ".ogg", ".wav");$song_files = array();$txtfile = "songs.txt";/* Puts all the names of the files from $dir in $files THIS ONLY WORKS ON PHP 5, YOU'VE GOT TO USE OTHER FUNCTIONS IN LOWER VERSIONS, CHECK PHP'S MANUAL*/$files = scandir($dir);/*Reset the pointer of the array*/reset($files);/*Create the txt file. If it exsists, i will be overwritten. Check PHP manual for other modes that are best suited for what you want to do*/$txthandle = fopen($txtfile, "w");/*Ordered list HTML tag*/echo "<ol>\n";foreach ($files as $file) { foreach ($file_types as $type) { /* Checks the last 4 letters of the file name to see if it matches with one from the file _types array*/ if (substr($file, -4) == $type) { /*This var is intended to be used with the txt output*/ $id = $id + 1; /*Echo List item tag with name of the song*/ echo "<li><a href=\"" . $dir . "/" . $file . "\">" . $dir . "/" . $file . "</a></li>\n"; /*Write to the txt file. The line break is for windows. For Unix is only "\n" and for Mac only "\r"*/ fwrite($txthandle, $id . ". " . $dir . "/" . $file . "\r\n"); } }}fclose($txthandle);echo "</ol>\n";?> Edited June 6, 2006 by facugaich Link to comment Share on other sites More sharing options...
willsradio Posted June 1, 2006 Author Share Posted June 1, 2006 Huge thanks facugaich for the help, I saw you working away on the topic, so thanks again huge respect you for putting the effort forth. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now