Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating links based on a varied number of files. 1

Status
Not open for further replies.

milage

Programmer
Jul 13, 2001
58
US
Hi,

I need to write a CGI script that creates hyperlinks to files in a directory.

Say I have two files in a sub-directory "doc" on my website:

Test1.pdf
Test2.pdf

And I want to search through the directory "doc" and then create a hyperlink on the page for every file that is in the directory.

This would mean that say someone added the file
Test3.pdf this would automatically create a hyperlink for this file when the page was accessed. Rather than having to update a static html page every time or embedding the actualy links in a cgi script.

Any help on this one would be very much appreciated. I hope my description is clear enough!

From Rob







 
# do the normal html content-type, HTML, HEAD, TITLE stuff

opendir(DOCS,"./docs") or die "Failed to open DOCS dir, $!\n";
@files = grep !/^\.\.$?/, readdir DOCS; # get all files except '.' and '..'
closedir DOCS;

# point the red part at your docs dir
$ = '[red]
Code:
[URL unfurl="true"]http://www.yourserver.com/some/dir/[/URL]
[/red]';
print &quot;<p>\n&quot;;
foreach $file (@files)
{
$href = $print &quot;<a href=\&quot;$href\&quot;>$file</a><br>\n&quot;;
}
print &quot;</p>\n&quot;;

I have not run this, but it should be close.

HTH


keep the rudder amid ship and beware the odd typo
 
wow, that was quick.

Haven't got it to work yet but I'm working on it.
One problem is that I won't be able to hardcode in the full root url.

Is it possible to make this just a relative url from the location of the cgi page?

Rob
 
It works!

Thank you very very much for your help.

From Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top