Jump to content

[SOLVED] Pick a pic


Brian W

Recommended Posts

I am trying to create a function that will find the thumbnail for a given property for a real estate website I am working on. In a folder called images/ I have the pics named first by the reference number to the property then a unique number (example: 101_2.jpg is the second picture for the property 101)

For every property, there is a thumbnail pic named ###_thumb.jpg (101_thumb.jpg)

So, what I figured I should do is pull the extension off of the name using explode (was using list and split, but moved to explode hoping that it would fix my problem... it didn't of course) then I try to find a match of the ref number I input into the function that has "_thumb" on it.

Here is what I have,

<?php
function findthumb($IDset){
$dir= 'images/';
foreach (glob($dir."*", GLOB_NOCHECK) as $filename) {
	$listingID = explode(".", $filename);
		if($listingID[0] == $IDset."_thumb") {
			$img = $filename; }
} return $img;
}

?>
<?php $id = "101"; echo findthumb($id); ?>

I'm using 101 as a test again.

I've echod every variable out and every thing seems to work up to

if($listingID[0] == $IDset."_thumb") {
$img = $filename; }

Even though $listingID[0] echos as 101_1, 101_2, 101_thumb    Its *seems* not catching as being == to $IDset

any input appreciated.

Link to comment
https://forums.phpfreaks.com/topic/126776-solved-pick-a-pic/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.