Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
cgi script to crete a web page of my files
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
brent_weaver
Guru
Guru


Joined: 01 Jul 2004
Posts: 510
Location: Burlington, VT

PostPosted: Mon Jan 02, 2006 1:50 am    Post subject: cgi script to crete a web page of my files Reply with quote

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
View user's profile Send private message
d_m
Guru
Guru


Joined: 12 Jun 2003
Posts: 570
Location: Philadelphia, PA, USA

PostPosted: Mon Jan 02, 2006 2:29 am    Post subject: Reply with quote

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
View user's profile Send private message
brent_weaver
Guru
Guru


Joined: 01 Jul 2004
Posts: 510
Location: Burlington, VT

PostPosted: Thu Jan 05, 2006 3:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
d_m
Guru
Guru


Joined: 12 Jun 2003
Posts: 570
Location: Philadelphia, PA, USA

PostPosted: Thu Jan 05, 2006 10:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum