【发布时间】:2015-04-03 23:42:16
【问题描述】:
我正在努力在扫描目录时仅将图片文件显示为图片而不是链接。这是我用来查找文件的内容:
$images=glob(getcwd().'/*{jpeg,gif,png}', GLOB_BRACE);
$pattern=implode("<br>", $images)."<br>";
这给了我这个:
/students/levans10/public_html/cs130a/images.gif
/students/levans10/public_html/cs130a/jpg-44.png
如何将这些行中的每一行都称为字符串?
这是我的整个代码对我不起作用:
<?php
function showImage() {
$filelist = glob(getcwd()."/*");
$path= getcwd();
$array = explode("/", $path);
$filename=implode("/", array_slice($array, 4));
$user=implode("/", array_slice($array, 2, 1));
$images=glob(getcwd().'/*{jpeg,gif,png}', GLOB_BRACE);
$pattern=implode("<br>", $images)."<br>";
echo implode("<br>", $images);
if ($filelist != false) {
print "<p>Here are the folders and files in".getcwd().":</p>";
foreach ($filelist as $file) {
if(ereg($pattern, $file)) {
$url = "http://hills.ccsf.edu/~".$user."/".$filename."/" . substr($file, strrpos($file, '/') + 1);
print "<a href=".$url."><img src=".$url." height='100' width='100'></a><br><br>";
}
if(!ereg($pattern, $file)) {
$url = "http://hills.ccsf.edu/~".$user."/".$filename."/" . substr($file, strrpos($file, '/') + 1);
print "<a href=".$url.">".$url."</a><br><br>";
}
}
} else {
print "<a href=".$url.">".$url."</a><br><br>";
}
}
showImage();
?>
我尝试使用:
(!feofif(ereg($pattern, $file))))
但这不是 !feof 的正确使用,因此它会显示图片但随后会发出大量其他警告。
【问题讨论】: