Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7964907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:01:05+00:00 2026-06-04T06:01:05+00:00

I am new to php and i’m creating an image gallery. the code i

  • 0

I am new to php and i’m creating an image gallery. the code i have written works and it works well but i need to upload files to the server. the gallery works by loading a thumbnail image onto the page and when the thumbnail is clicked a fancybox pop up will open and will display a high res version of the thumbnail.

there are 2 images in the folder structure. photos live in /gfx/photos and thumbnails live in /gfx/photos/thumbs. i am trying to write a PHP script that check if new photos have been added to the /gfx/photos/ folder and automatically creates a thumbnail in the /gfx/photos/thumbs folder. I can do the resize part but i need help comparing 2 files against each other. the thumbnails and the photos have exactly the same name they just live in separate locations.

i have an image array that works like this:

<?PHP
    $dir = "gfx/photos/thumbs";
    $files = scandir($dir);

    foreach ($files as $key => $value);
    $result = count($files);
    for ($i = 0; $i < $result; $i++) {
      /* loads appropriate code for every file... */
    }

?>

could this code be used to check files against each other or should i use different code.

Thanks for your help people!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:01:06+00:00Added an answer on June 4, 2026 at 6:01 am

    Here’s a simple way to get this result and will work great so long as the directory doesn’t fill up with millions of images, though if you are able to have millions of images you should probably break them up into smaller directories.

    Since scandir returns back an integer indexed array you would normally have to do some array searching to find your image. However. If you do this using array_flip:

    $image_name = "some_image.jpg";
    
    $dir = "gfx/photos/thumbs";
    $files = scandir($dir);
    
    $files = array_flip($files); // makes the values = to keys and keys = values
    
    // now you have an 0(1) look up table that you can simply check if the key exists
    // which, now that we flipped the array, are the file names
    if(!isset($files[$image_name])){
        // create the thumbnail etc
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Yields that there is already new PHP framework written as extension. http://code.google.com/p/yafphp ,
I have old.htm and new.htm on a directory, and I need to load file.php
I have the following string: $/Mycollection/Branches/Dev/New/php/MySite/src/MySite/somefolder/src/sad.php I need to create regex pattern and take
Every 72 hours I upload a new PHP file to my server. (well actually
Am new to php... I have been battling on my dynamic checkboxes in such
I'm new in php I have a json I decoded it and wrote the
I am new to PHP, so I have a basic question. I have this
I have php 5.2.11 on my server. Should I upgrade to the new PHP
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a new php page and I'm using wordpress for my website. From

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.