0

I have two folders, 1)- 23feb2016 and 2)- 23feb2016. I want to get one image from folder1 and one from folder2 , the image name must be unique, like userid etc.

This is my html code:

<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>

same image will be display in model and by submiting it will send flag to DB

7
  • 5
    my html code is this where? Commented Mar 7, 2016 at 6:46
  • 1
    Have you tried anything? Commented Mar 7, 2016 at 6:48
  • 1
    Save image name with timestamp then Commented Mar 7, 2016 at 7:05
  • Use date('Y-m-d-H-i-s') . '_' . uniqid() for unique image name Commented Mar 7, 2016 at 7:07
  • give table structure please . Commented Mar 7, 2016 at 7:14

1 Answer 1

2

You can use the following approach to find the unique files.

//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));
}

Now the Array Variable $UniqeImage[] contains the Unique file names using this you can construct the 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>");
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for help the folders must be dynamically changing as per date .. means each date have own folder of images and the name of folder will be the date and image name will be userid.jpg like this .
Happy with your reply. The answer really fulfilled your requirement means, then mark it as your Answer.
it displays all the images while i have to check for the image with folder name and image with transiction ,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.