我写了一个简单的图片库,用于检查文件夹并显示我有代码的文件夹中的所有图像以删除。和..但它不工作,我不明白为什么任何帮助将是伟大的,因为我是PHP的dir函数的新手。我有链接围绕链接的灯箱标签因此额外的回声代码如下:
<?
// USER OPTIONS DEDFINED HERE
$dir = "img/"; //folder with images
$height ="196px"; //image height on page its displayed in full in lightbox
$width ="320px"; //image width on page its displayed in full in lightbox
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gallery</title>
<link href="css/css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
</head>
<?
//open directory
if ($opendir = opendir($dir));
{
//read dir
while (FALSE !== ($file = readdir($opendir)))
{
if ($file!="."&&$file!="..")
echo "<div class='imgwraper'>";
echo"<a href='$dir$file' rel='lightbox[gallery]' title='$filename'>";
echo "<img src='$dir$file' alt='' width='$width' height='$height'/>";
echo"</a>";
echo "<div class='name_box'>";
echo current(explode('.', $file));
echo "</div>";
echo "</div>";
}
closedir($opendir);
}
?>
先谢谢
路易斯
答案 0 :(得分:2)
if ($file!="."&&$file!="..")
后您没有大括号,if
语句仅适用于echo "<div class='imgwraper'>";
的第一行。
将所有内容包裹在大括号中:
while (FALSE !== ($file = readdir($opendir)))
{
if ($file!="."&&$file!="..") {
echo "<div class='imgwraper'>";
echo"<a href='$dir$file' rel='lightbox[gallery]' title='$filename'>";
echo "<img src='$dir$file' alt='' width='$width' height='$height'/>";
echo"</a>";
echo "<div class='name_box'>";
echo current(explode('.', $file));
echo "</div>";
echo "</div>";
}
}
顺便说一下,您可以考虑使用glob
来简化代码。
答案 1 :(得分:0)
不要忘记用if括号括起if语句。
while (FALSE !== ($file = readdir($opendir)))
{
if ($file!="."&&$file!=".."){
echo "<div class='imgwraper'>";
echo"<a href='$dir$file' rel='lightbox[gallery]' title='$filename'>";
echo "<img src='$dir$file' alt='' width='$width' height='$height'/>";
echo"</a>";
echo "<div class='name_box'>";
echo current(explode('.', $file));
echo "</div>";
echo "</div>";
}
}
晒。