Brian W Posted October 2, 2008 Share Posted October 2, 2008 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 More sharing options...
Brian W Posted October 2, 2008 Author Share Posted October 2, 2008 Never mind, figured out what the problem was. I echod out $listingID[0] again and realized that it wasn't coming out as ###_thumb, it was images/###_thumb. so I just had to add $dir onto my if( == ) statement Link to comment https://forums.phpfreaks.com/topic/126776-solved-pick-a-pic/#findComment-655717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.