Jump to content

File_Exists


Philwn

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.