我一直在努力解决这个问题。
我发现这段代码运行良好,取自官方 php 网站。但是,如果我将一张图像和一个 pdf 放在文件夹中,它就会显示出来。照片。
我需要一种非常简单的方法来扫描目录,检查其是否为 jpg,然后只显示一张照片。
请告诉我如何更改以下代码,或者我是否需要为我的需要编写一些不同的东西。
<?php // no access
.............
// globals
.............
// make article title lower case
$str = strtolower($articleTitle);
$files= scandir("images/gallery/".$str."/");
$photos = array();
for ($x=0; $x<count($files); $x++){
$files[$x]="images/gallery/".$str."/".$files[$x];
if (is_dir($files[$x])){
$thisfolder=scandir($files[$x]);
for ($f=0; $f<count($thisfolder); $f++)
if (strpos(strtolower($thisfolder[$f]), ".jpg"))
$photos[]=$files[$x]."/".$thisfolder[$f];
}
}
$rand=rand(0, count($photos)); ?>
<img src="includes/crop.php?src=<?php echo $photos[$rand];?>&h=115&w=650&q=90" title="<?php echo $photos[$rand];?>" />
再次提前感谢:)约翰