我有两个文件夹,1)- 23feb2016
和2)- 23feb2016
。
我想从folder1
获取一张图片,从folder2
获取一张图片,图片名称必须是唯一的,例如userid
等。
这是我的HTML代码:
<div class="col-md-12">
<div class="col-md-6">
<Image src="../images/registered/20115.jpg" style="width: 100%; height: 100%"></Image> Registered
</div>
<div class="col-md-6">
<Image src="../images/registered/20115.jpg" style="width: 100%; height: 100%"></Image> Attendance
</div>
</div>
答案 0 :(得分:2)
您可以使用以下方法查找唯一文件。
//path to directory to scan
$directory1 = "./folder1/";
$directory2 = "./folder2/";
//get all Image files with a .jpg extension.
$jpgFolder1 = glob($directory1 . "*.jpg");
$jpgFolder2 = glob($directory2 . "*.jpg");
$UniqeImage[];
if(($jpgFolder1 != null) && ($jpgFolder2 != null))
{
$UniqeImage = array_unique(array_intersect($jpgFolder1, $jpgFolder2));
}
现在,Array Variable $ UniqeImage []包含使用它的唯一文件名,你可以构造HTML
foreach($UniqeImage as $img)
{
echo("<div class='col-md-12'>");
echo(" <div class='col-md-6'>");
echo(" <Image src='../images/Folder1/" . $img . ".jpg' style='width: 100%; height: 100%'></Image> Registered");
echo(" </div>");
echo(" <div class='col-md-6'>");
echo(" <Image src='../images/Folder2/" . $img . ".jpg' style='width: 100%; height: 100%'></Image> Attendance");
echo(" </div>");
echo("</div>");
}