Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i am making a music website where people
can download latest songs for that i will upload
songs through ftp but i have to make link for
each song seperately. so i want a script or
method so that the links will be formed
automatically when i upload any song. i am
new to this but i know scripting a bit. please
help me.

<?php foreach(glob(path to files/*.ext) as $file) { echo "<a href='" . $file . "'>" . $file . "</a><br />"; } ?>Something like above would echo any file names found in the path relative to the document root. It's not going to form links as you upload songs though; however, when a user accesses the resource, the list would be current. If need be, you could use a meta refresh to load the page at a set interval.
Note: using glob as above will spit out an error on an empty directory, so you'd want a index.html file or something and ignore it when you generate the file list.
Hope that helps.

i can you be pls simple and specific to me what r u saying bcoz i
don't understand where to put it in site and how to use this
script.
thank u

The code could go In the page that visitors would use to access the site. For a basic example, if you have your site located at mysite.com and your songs are stored in mysite.com/songs
<html> <head> <title>Song List</title> </head> <body> other stuff <?php foreach(glob("songs/*.mp3") as $file) { echo "<a href='" . $file . "'>" . substr($file, strpos($file, '/') + 1) . "</a> " . filesize($file) . " bytes<br />"; } ?> other stuff </body> </html>As I mentioned before, the above isn't going to show your songs as you add them by ftp, but it will be updated each time a visitor requests the page.
Hope that helps

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |