You are here: Re: Link html files « HTML « IT news, forums, messages
Re: Link html files

Posted by feed_sheep on 07/29/06 05:10

"Michael Laplante" <nowhereman@twilightzone.net> wrote in message
news:iywyg.170543$S61.127655@edtnps90...

> Don't think this is the ticket. I want multiple HTML files -- one per
> image -- with a link at the bottom of each that takes me to the next one
> in the series. There are web photo album programs that do this, but they
> assume that all your photos are in order and ready to go. I may have to
> add photos in the middle of the list at a later date which would throw all
> the sequential links out of whack.


It seems like a lot of work and potential maintenance to create multiple
HTML files. If you have a web server with PHP installed (and pics inside
the web root), you might try this script I wrote. (Please note that I'm an
amateur at PHP; I'm sure this could be optimized and cleaned up a lot.)

Name the file gallery.php. Edit the $dir value to the proper location.

<?php
$dir = "path/to/pics/";
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file != "." && $file != "..") {
$file_list[] = $file;
}
}
closedir($dh);
if ($_GET['pic'] != '') {
$key = array_search($_GET['pic'], $file_list);
$image = "<img src='$dir$file_list[$key]' alt='$file_list[$key]'>";
$next_key = $key + 1;
$next = "<a href='gallery.php?pic=$file_list[$next_key]'>Next</a>";
$prev_key = $key - 1;
$previous = "<a
href='gallery.php?pic=$file_list[$prev_key]'>Previous</a>";
$pic = $_GET['pic'];
} else {
$image = "<img src='$dir$file_list[0]'>";
$key++;
$next = "<a href='gallery.php?pic=$file_list[$key]'>Next</a>";
$previous = '';
$pic = $file_list[0];
}

}

echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 //EN\"
\"http://www.w3.org/TR/html4/strict.dtd\">
<html>
<head>
<title>$pic</title>
</head>
<body>
<div style='width: 90%; margin: 0 auto; text-align: center;'>
$image
<h1>$pic</h1>
<p>$previous $next</p>
</div>
</body>
</html>";
?>

David

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация