Google Answers Logo
View Question
 
Q: Creating a web page to display links form a folder ( Answered 5 out of 5 stars,   2 Comments )
Question  
Subject: Creating a web page to display links form a folder
Category: Computers > Programming
Asked by: joe_d-ga
List Price: $50.00
Posted: 28 May 2004 10:20 PDT
Expires: 27 Jun 2004 10:20 PDT
Question ID: 353205
I have been asked to create a web site for our homeowner's
association. I would like to have a page of archived news articles
from the local papers.

I have a collection of these in a folder as html files. I add to them
several times per week. Each file's name is descriptive of the
contents and begins with the date in "yymmdd" format.

What I would like is a web page that generates a listing of the files
in date order as hyperlinks to the articles (html files) themselves.
This would allow me to add or delete articles at wil without having to
change the displaying web page.

An additional wrinkle would be to have the date display in normal
manner (e.g. 05/13/04), but that is not really necessary at this time.
Answer  
Subject: Re: Creating a web page to display links form a folder
Answered By: tox-ga on 28 May 2004 13:24 PDT
Rated:5 out of 5 stars
 
Hi there,

I can provide you with a web page that does exactly what you'd like
(including the date display).  This, however, is impossible using
strictly HTML.  There are many programming languages that could do
what you're requesting, but perl is the most common for this kind of
task.  Thus, the following is the answer using perl:

==If you have 'Server Side Include'==
Step 1:  
Download the following file and unzip the content ga.pl
http://www.maxlin.ca/tos/ga/ga.zip

Step 2:
Put in the following line in the HTML file whereever the list of links should go:
<!--#include virtual="ga.pl" -->

If the file name is "041203Article 1.html" it will display "04/12/03 - Article 1"

Step 3:
Save the HTML file as .shtml (this is so that the server knows it's
Server Side Include)

Step 4:
Put the SHTML page that you want the list to appear on, the articles,
and the file ga.pl in the same folder.

During this step, you should CHMOD ga.pl to a value of 755. You can do
this using an FTP client when you upload it to your server.

Also, please note that at the top of the perl file (ga.pl) it says
#!/usr/bin/perl
#
This may need to be changed depending on your server.  You will need
to ask your server administrator for this detail if it does not work.

For a sample of the final product, please refer to http://www.maxlin.ca/tos/ga/

==If you do not have Server Side Include==
If you do not have SSI, I will need to see your index.html so I can
insert it into the perl file.  The html would basically have to be
copied and pasted into the perl file so that the perl file produces
the static index file, with the dynamic links in the middle.


If you have any problems, or need any additional information, please
let me know; I will be more than happy to help you until you are
completely satisfied.  Please use the "Request for Clarification of
Question" feature on this page for further questions.

Best regards,
Tox-ga

Request for Answer Clarification by joe_d-ga on 28 May 2004 15:44 PDT
Well, I love your solution as it appears on the sample, but I can't
get the perl script to work properly. I uploaded a half dozen html
pages to a clear folder on the server, then uploaded the shtml file
and the ga.pl file, set the CHMOD on the ga.pl file to 755 and the
resulting html page appears to be displaying the included file instead
of executing it. Here is the link:
http://acorn.he.net/~rotaryc/Highlands/index.shtml

I checked, and Hurricane electric (www.he.com) uses #!/usr/bin/perl
for the top of the perl file.

I must be missing something simple.

Joe Donohue

Clarification of Answer by tox-ga on 28 May 2004 17:21 PDT
I took a look at the HE page for server-specific details on running scripts.

I think that your server will only run scripts in the /cgi-bin
directory; that is, http://acorn.he.net/~rotaryc/cgi-bin so you should
move the perl file to that directory.  Remember to check that it is
still chmod'ed to 755 after the move.

You should change the reference in the SSI command in the index.shtml
file appropriately, like <!--#include virtual="../ga.pl" -->

If that doesn't work, you could try changing it to <!--#exec
cmd="/home/rotaryc/cgi-bin/ga.pl"-->  (it may be /home/~rotaryc...)

If none of these work, let me know.

Request for Answer Clarification by joe_d-ga on 28 May 2004 19:35 PDT
Wow, this has turned out to be a hassle but please stick with me. I
tried as many permutations of your suggestions as I could think of. I
created the files Index.shtml through Index6.shtml without success.
They are on the same link.

Here is what I included in each:

Index.shtml  <!--#include virtual="ga.pl" -->
Index1.shtml <!--#include virtual="/~rotaryc/cgi-bin/ga.pl" -->
Index2.shtml <!--#include virtual="../ga.pl" -->
Index3.shtml <!--#exec cmd="/home/rotaryc/cgi-bin/ga.pl"-->
Index4.shtml <!--#exec cmd="/home/~rotaryc/cgi-bin/ga.pl"-->
Index5.shtml <!--#exec cmd="ga.pl"-->
Index6.shtml <!--#include virtual="/rotaryc/cgi-bin/ga.pl" -->

The first produces a listing of the pl file
The 2nd,3rd and 6th produce [an error occurred while processing this directive] 
The 4th and 6th produce Content-type: text/html 
The 5th produces a blank

I am sorry to keep on this but I really want to make it work.

Joe Donohue

Request for Answer Clarification by joe_d-ga on 28 May 2004 20:34 PDT
It appears that Index3 and 5 are working in that the file ga.pl is
actually being accessed, but none of the html files are being
displayed.

Joe

Clarification of Answer by tox-ga on 28 May 2004 22:02 PDT
Hey,
Don't worry, we'll get this working.  Perl can be tricky the first
time you install a script on a new server, but I've done it dozens of
times so I know all the possible things that could go wrong and their
solutions.

It is great that 3 and 5 work.  In fact, I am sure I have the answer. 
I can't see the links you posted though.  I think your server only
lets you view folder contents because all I see is "file not found". 
In any case, when I told you to move the perl file to the /cgi-bin
directory, I forgot that the perl file checks the directory it is in
for .html files.

There is a line in ga.pl that reads:
opendir DIR, "." or die "Can't open directory $dir: $!\n";
I would like you to change it to:
opendir DIR, "../Highlands" or die "Can't open directory $dir: $!\n";

That way, it will check the Highlands directory for html files in the
yymmddDescription.html format.

This should work with 3 and 5, the ones that already worked, but if it
for some reason doesn't, please don't hesitate to ask me again.

Cheers,
tox-ga

Clarification of Answer by tox-ga on 28 May 2004 22:03 PDT
Oh, and also I should remind you to CHMOD the file again when you
upload the changed version.  I've wasted hours chasing little things
like this before.

Request for Answer Clarification by joe_d-ga on 29 May 2004 08:10 PDT
I knew this would happen. The original solution you sent would have
worked except for the fact that I specified the files as html when
they were actually htm.

I could not get any variation of the 
<!--#include virtual="ga.pl" -->
to work, but I was able to get the 
<!--#exec cmd="ga.pl"--> to work fine, so the pl file did not need to
be in the cgi-bin directory after all.

Then, I complicated things by sending you the wrong link. I had
incorrectly named the directory "HIghlands" (with a capital "I") I
fixed that and here is the correct link:
http://acorn.he.net/~rotaryc/Highlands/

The index1.shtml file works.

Now, for 2 final things:
1. I don't seem to be able to unhook the "Content-type: text/htm" from
the first listing, and
2. How can I adjust the pl file to sort backward (latest item first)?
I changed the order of the printout to print $2, $3, $1 to display in
normal date sequence but I just need to have them sorted backwards.

Thanks
Joe Donohue

Clarification of Answer by tox-ga on 29 May 2004 11:58 PDT
Hi Joe,

I'm glad we got this all working properly.  As for reversing the
order, this has a simple fix:
The line reading:
@files = sort @files;
should be changed to:
@files = reverse sort @files;

As for the printed Content-type header, I'm surprised that it is
showing up.  My first suspicion is that it should read:
Content-type: text/html\n\n
even though you are using .htm files.  'text/htm' is not a valid
content type as far as I know.  However, that would suggest that your
server fixed the script on its on by adding a content-type header when
no valid ones were found.

So, my suggestions to you are this:
1) Change the part reading
print "Content-type: text/htm\n\n";
to
print "Content-type: text/html\n\n";
2) If this results in 'Content-type: text/html' being printed at the
top of the page still, then I would suspect that your server
automatically adds headers, so the one we're printing is redundant and
you should try removing the line altogether.

After these steps, eveeything should work perfectly.  However, these
are computers we are talking about, so we can never tell.  If
something doesn't work right after this, you may of course feel free
to ask me for help.

Best regards,
tox-ga
joe_d-ga rated this answer:5 out of 5 stars and gave an additional tip of: $10.00
Excellent final answer. Perfectly fits my needs and took less than a
day in total. Good follow through.

Comments  
Subject: Re: your link
From: tox-ga on 28 May 2004 16:52 PDT
 
Yea, it probably is something simple.  However, when I click your
link, I get a "file not found" error.  Did you take the page down?

To clarify, your problem is that it displays the perl file instead of
the links that should be generated?
Subject: Re: Creating a web page to display links form a folder
From: joe_d-ga on 28 May 2004 20:40 PDT
 
Here is the main link:
http://acorn.he.net/~rotaryc/HIghlands/index.shtml

I have uploaded files from Index1.shtml to Index6.shtml with various
different calls for the pl file, as described above. It appears that
Index3.shtml and Index5.shtml are actually being accessed but not
displaying the html files.

I have deleted index.shtml to allow you to display the entire folder.

Joe Donohue

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy