View previous topic :: View next topic |
Author |
Message |
brent_weaver Guru
Joined: 01 Jul 2004 Posts: 510 Location: Burlington, VT
|
Posted: Mon Jan 02, 2006 1:50 am Post subject: cgi script to crete a web page of my files |
|
|
Hello all. I am new to programming in Perl and I was wondering if I could get some advice. I would like to create a script that will dynamicly present in HTML and index of my files. These "files" would of course be href links. I am trying to put my family photos on the web and can host at home for I have static IP... so...
I would think that I am going to need to write out a temp file/pipe with the fully qualified filename paths, read it into a loop and create/print the html link.
I am shure there is a relatively easy way to do this! Thanks! _________________ Brent Weaver |
|
Back to top |
|
|
d_m Guru
Joined: 12 Jun 2003 Posts: 570 Location: Philadelphia, PA, USA
|
Posted: Mon Jan 02, 2006 2:29 am Post subject: |
|
|
Don't even both with temp files. You can just get the directory contents in perl and create links from them, then print the output to the browser. If you have CGI turned on, something like this would work (find all JPG files in BASEDIR, and print a list with all the links):
Code: | #!/usr/bin/perl
use warnings;
use strict;
my $BASEDIR = "/var/www/htm/images";
sub file_to_link {
my $file = shift;
my $link;
#write some code to change a path listing into a link
return $link;
}
my @files = split("\n", `find $BAREDIR -type f -name '*.jpg'`);
print "Content-type: text/html\n";
print "\n";
print "<html>\n<body>\n<ul>\n";
foreach my $file (@files) {
my $link = file_to_link($file);
print "<li>$link</li>\n";
print "</ul>\n</body>\n</html>\n"; |
Good luck. _________________ The name that can be named is not the eternal name. |
|
Back to top |
|
|
brent_weaver Guru
Joined: 01 Jul 2004 Posts: 510 Location: Burlington, VT
|
Posted: Thu Jan 05, 2006 3:29 pm Post subject: |
|
|
thanks for the great info. What variable will I be using as the full path to the file? I can get teh HTML code to call a file link, just do not know what the var is!!!
I find perl to be very difficult to understand. I am coming from a VMS background where things make sense to me... _________________ Brent Weaver |
|
Back to top |
|
|
d_m Guru
Joined: 12 Jun 2003 Posts: 570 Location: Philadelphia, PA, USA
|
Posted: Thu Jan 05, 2006 10:21 pm Post subject: |
|
|
In the sample code I wrote, $file is the path to the file, from the place the find started (/var/www/htm/images). So...
"/var/www/html/images/" . $file
would be the absolute path. _________________ The name that can be named is not the eternal name. |
|
Back to top |
|
|
|