creating automated links

July 29, 2009 at 07:47:38
Specs: linux
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.

See More: creating automated links

Report •

July 29, 2009 at 10:09:31

   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.

Report •

July 29, 2009 at 10:23:21
thanx so much for your answer i will try it.

Report •

July 30, 2009 at 03:07:36
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
thank u

Report •

Related Solutions

July 30, 2009 at 08:31:50
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 and your songs are stored in

<title>Song List</title>
other stuff

   foreach(glob("songs/*.mp3") as $file) {
      echo "<a href='" . $file . "'>" . 
           substr($file, strpos($file, '/') + 1) . "</a> " . 
           filesize($file) . " bytes<br />";

other stuff

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

Report •

Ask Question