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