PHP readdir 不断显示点
我编写了一个简单的图像库脚本,女巫检查文件夹并显示文件夹中的所有图像,我有代码删除 .并且..但它不起作用,我不明白为什么任何帮助都会很棒,因为我对 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);
}
?>
提前感谢
刘易斯
I have written a simple image gallery scrip witch checks a folder and displays all the images in the folder i have code to remove the . and .. but its not working and I cant see why any help would be great as im new to the dir functions in PHP. I have lightbox tags surrounding the link hence the extra echo's The code is below:
<?
// 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);
}
?>
Thanks in Advance
Lewis
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
if ($file!="."&&$file!="..")
后面没有大括号,if
语句仅适用于第一行 echo "
";
。将所有内容都用大括号括起来,如下所示:
顺便说一句,您可以考虑使用
glob
来进一步简化代码。You have no braces after
if ($file!="."&&$file!="..")
, theif
statement is only applicable for the first line ofecho "<div class='imgwraper'>";
.Wrap everything in braces like so:
By the way, you could consider using
glob
to simplify your code a bit more.不要忘记将 if 语句括在大括号中。
谢伊。
Don't forget to wrap your if statement in curly brackets.
Shai.