IT.COM

Link creation

Spaceship Spaceship
Watch
Does anybody know a good program that automatically creates hypertext links from a specified directory. For example if I have a dir full of many txt files and I want code that links to all of those files without typing each one in manually.

Thanks.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
I havn't used many editor programs so I don't know if any of them have the ability to do that or not.

There probably is a program designed specifically for that purpouse out there somewhere though, but I'm not sure where. If I come across something I'll let you know.

I don't think it would be real hard to create a script to do it though. :)
 
0
•••
mmmm. the only one i can think of that might be able to do that is dreamweaver. like deadserious, i will look around and see if i can't find one as well.
 
0
•••
thanks guys, ive looked around for ages cant find anything
 
0
•••
Okay you gave me a little idea so here's my simple link creator.

Code:
#!/usr/bin/perl -w
#SIMPLE LINK CREATOR 

use CGI::Carp qw(fatalsToBrowser);

#the server path to the directory with the files
my $dirpath = '/path/to/directory';

opendir DIR, $dirpath || die $!;
my @directory = readdir DIR;
closedir DIR;

print "Content-type: text/htmlnn";
foreach my $file (@directory) {
my $links = qq~<a href="$file">$file</a><br><br>n~;
print $links;
}

That will automatically print out a link to each file in which ever directory you speicify as the $dirpath. It will print out hidden files too, but shouldn't be hard to fix that. Anyways maybe something like that could work for you if you have Perl / Cgi acccess.

If you want to give it a try you can copy and paste the code into a text file and save it as whateveryouwant.cgi and upload it to where ever you're allowed to run cgi scripts and chmod to 755 and call it up in your browser. Don't forget to change the $dirpath to the directory which has your files in it. :)
 
0
•••
Thanks heaps for your help
I am getting internal errors or no errors and no html file :(
I have 777 the dir where I want the html file to be created which contains the txt's
I think it may be because I dont have the server path as I am using a webhost and there is no info.
Is it possible just to use the web address as the dir path?
 
0
•••
You need to use the abosolute path to the directory. Your web host should be able to tell you the path or atleast have it listed in their faq somewhere.

You can try saving this code in a text file:

<?php
phpinfo();
?>

Save it as info.php and upload it and call it up in your browser and scroll down to where you see:

Apache Environment
Variable Value
DOCUMENT_ROOT /your/abosolute/path/should/be/here

That is if your host is using apache. :)
 
0
•••
I forgot to mention that you need to make sure and upload it in ascii mode. But if you had it working and just got nothing no errors or nothing then that's probably because you don't have the right path to your directory.

Also if you find this in your php info page:
_SERVER["SCRIPT_FILENAME"] /the/absolute/path/should/be/listedhere/info.php

That sholuld give you the path you need, just take off the filanme.php extension on the end. :)
 
0
•••
Done!
Works perfectly and provides me with exactly what I need.
Thanks so much you have saved me alot of time and tedious coding.
With a few options this could be a good script to release, I couldn't find anything like it anywhere.

Thanks again. :D
 
0
•••
Your Welcome! Glad it worked for you. :) Maybe I'll work on it and make it a little more customizable. So if you have any suggestions feel free to post them here.

B-)
 
0
•••
I guess if you can make the HTML output customizable and make it automatically generate and update for specified directories it would be a very usefull script. For example if more files were added it would auto add these to your html. Some security options would be needed though.

Would be a great script :)
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back