bluewalrus
10-07-2008, 01:04 AM
I have the code below which i got from the looking for a code or script board but no one there is answering now. The code is suppose to read my directory called images and write <a href="image# in directory"><img scr="image# in directory"></a>
Then keep writing till it gets to the last image. This is the code I got but it is only writing 1 comment tag(<!-- ... -->) . i have about 50 images in the images directory and 3 other directories with in that directory would that make an error?
http://www.bluewalrus.net/testing.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
define('IMG_DIR', 'images/');
function is_image($fn) {
return in_array(pathinfo($fn, PATHINFO_EXTENSION), array('jpg', 'jpeg', 'png', 'gif'));
}
$imgs = array();
$dir = opendir(IMG_DIR);
while ($ff = readdir($dir))
if (is_image($f))
$imgs[] = IMG_DIR . '/' . $f;
closedir($dir);
?>
<!-- ... -->
<?php foreach ($imgs as $img) { ?>
<a href="$img">
<img src="$img" alt="pathinfo($img, PATHINFO_FILENAME);">
</a>
<?php } ?>
</body>
</html>
Any ideas or suggestions i appreciate thanks.
Then keep writing till it gets to the last image. This is the code I got but it is only writing 1 comment tag(<!-- ... -->) . i have about 50 images in the images directory and 3 other directories with in that directory would that make an error?
http://www.bluewalrus.net/testing.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
define('IMG_DIR', 'images/');
function is_image($fn) {
return in_array(pathinfo($fn, PATHINFO_EXTENSION), array('jpg', 'jpeg', 'png', 'gif'));
}
$imgs = array();
$dir = opendir(IMG_DIR);
while ($ff = readdir($dir))
if (is_image($f))
$imgs[] = IMG_DIR . '/' . $f;
closedir($dir);
?>
<!-- ... -->
<?php foreach ($imgs as $img) { ?>
<a href="$img">
<img src="$img" alt="pathinfo($img, PATHINFO_FILENAME);">
</a>
<?php } ?>
</body>
</html>
Any ideas or suggestions i appreciate thanks.