Computing.Net > Forums > Web Development > creating automated links

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

creating automated links

Reply to Message Icon

Name: shara
Date: July 29, 2009 at 07:47:38 Pacific
OS: linux
Subcategory: PHP
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: July 29, 2009 at 10:09:31 Pacific
Reply:

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


0

Response Number 2
Name: shara
Date: July 29, 2009 at 10:23:21 Pacific
Reply:

thanx so much for your answer i will try it.


0

Response Number 3
Name: shara
Date: July 30, 2009 at 03:07:36 Pacific
Reply:

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


0

Response Number 4
Name: shutat
Date: July 30, 2009 at 08:31:50 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: creating automated links

creating a link directory www.computing.net/answers/webdevel/creating-a-link-directory/3536.html

PHP and Mysql to create Auto-links www.computing.net/answers/webdevel/php-and-mysql-to-create-autolinks/522.html

linking to spot on page www.computing.net/answers/webdevel/linking-to-spot-on-page/2545.html