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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Philwn Posted February 19, 2011 Author Share Posted February 19, 2011 ^Bump^ Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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++; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.