Philwn Posted February 18, 2011 Share Posted February 18, 2011 I am trying to do a loop which uses file_exists to check if an image exists and if so display it using the following code: <?php $i = 1; while ($i <= { $filename = $img_loc . "/hovers-800px/" . $image . "-" . $i . ".jpg"; if (file_exists($filename)) { ?> <a class="fuglybox" rel="gxr" href="<?php echo $filename; ?>"> <!--Main thumbnail image--> <img src="<?php echo $img_loc; ?>/product-detail-90px/<?php $image . "-" . $i . ".jpg"; ?>" alt="" width="90" height="90" /></a> <?php } $i++; } ?> I have echoed out $filename to check my directory structure and filename is fine and copied the echoed directory out. The structure is however Http://www.xxxxxx.com/img/filename.jpg. Could this be whats causing the problem? Link to comment https://forums.phpfreaks.com/topic/228093-file_exists/ Share on other sites More sharing options...
Philwn Posted February 18, 2011 Author Share Posted February 18, 2011 I spotted an error, I had missed an echo out of the thumbnail image to be displayed, I have removed the file_exists check and the code works fine, but with file_exists it doesnt Link to comment https://forums.phpfreaks.com/topic/228093-file_exists/#findComment-1176218 Share on other sites More sharing options...
Philwn Posted February 19, 2011 Author Share Posted February 19, 2011 ^Bump^ Link to comment https://forums.phpfreaks.com/topic/228093-file_exists/#findComment-1176703 Share on other sites More sharing options...
Pikachu2000 Posted February 19, 2011 Share Posted February 19, 2011 Have you echoed $filename to make sure it's a valid filesystem path? Link to comment https://forums.phpfreaks.com/topic/228093-file_exists/#findComment-1176707 Share on other sites More sharing options...
Philwn Posted February 20, 2011 Author Share Posted February 20, 2011 yes i haved echoed $filename and even copied the echoed filename and pasted in the address bar to check the path was correct Link to comment https://forums.phpfreaks.com/topic/228093-file_exists/#findComment-1177256 Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 Can you post the value it echoes? I suspect you're getting a path relative to the web root, not the filesystem root. Link to comment https://forums.phpfreaks.com/topic/228093-file_exists/#findComment-1177266 Share on other sites More sharing options...
Philwn Posted February 21, 2011 Author Share Posted February 21, 2011 http://www.mydomain.com/img/hovers-800px/image-1.jpg It is correct but this is why i asked if there was a problem using the absolute path with file_exists Link to comment https://forums.phpfreaks.com/topic/228093-file_exists/#findComment-1177492 Share on other sites More sharing options...
Philwn Posted February 21, 2011 Author Share Posted February 21, 2011 Ok i have tried without using the full directory path using the ../../ relative to the directory. <?php $i = 1; while ($i <= { $filename = "../../../../../img/hovers-800px/" . $image . "-" . $i . ".jpg"; if (file_exists($filename)) { ?> <a class="fuglybox" rel="gxr" href="<?php echo $filename; ?>"> <img src="../../../../../img/product-detail-90px/<?php echo $image . "-" . $i . ".jpg"; ?>" alt="" width="90" height="90" /></a> <?php } $i++; } ?> this still doesnt work yet if i remove the If (file_exists) it works fine although it will always display 8 images even if there are 5. <?php $i = 1; while ($i <= { $filename = "../../../../../img/hovers-800px/" . $image . "-" . $i . ".jpg"; ?> <a class="fuglybox" rel="gxr" href="<?php echo $filename; ?>"> <img src="../../../../../img/product-detail-90px/<?php echo $image . "-" . $i . ".jpg"; ?>" alt="" width="90" height="90" /></a> <?php $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/228093-file_exists/#findComment-1177548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.