Liz
2008-02-04 18:50:32 UTC
I have me an LAMP stack with apache 2.x and all the whistles and bells.
I have a department that produces PDF documents prolifically. They drop those documents in to a folder on a NAS which is then mounted to the web server and symbolically linked to /var/www/whatever. This is all set up and working as a poor mans publisher, but what you get when you log in that part of the site is the default apache index page. it lists the pdf docs, and you can link to them. As it should be. but UGLY, very ugly. Now, I am not looking for an entire content management system. Just a script, or a few lines of code that will allow me to list the files inside the directory in a
or something. Anybody. Help appreciated!
Three answers:
Chad L
2008-02-04 19:07:57 UTC
For instance:
my @pdf_files = glob("*.pdf");
Which you could then do something as simple as printing a header,and looping through the @pdf_files array like so:
print "Content-type:text/html\n\n";
print "...your html...";
my @pdf_files = glob("/var/www/whatever/*.pdf");
print "
- ";
- %s ",$file,$file);
foreach my $file (@pdf_files) {
print sprintf("
}
print "
print "...your html...";
Bob
2008-02-04 19:10:04 UTC
Untested but it should work. You may also want to add a test to see if the file name ends in .pdf or whatever you want.
$dir = "/var/www/whatever/";
?>
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
?>
}
?>
closedir($dh);
}
}
?>
?
2016-12-04 12:49:04 UTC
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.