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
https://forums.phpfreaks.com/topic/228093-file_exists/
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
https://forums.phpfreaks.com/topic/228093-file_exists/#findComment-1177548
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.