Page 1 of 1

Checking if file exists not working... why?

Posted: Thu Mar 23, 2017 4:49 am
by simonmlewis

Code: Select all

<?php
echo "<div class='width-narrow'>";
$count = 0;
$query = ("SELECT id, title, catname, subname, photoprimary FROM products WHERE pause <> 'on' ORDER BY title");
$result = $pdo->query($query);
while ($row = $result->fetch(PDO::FETCH_OBJ)) 
      {
      $count ++;
      $image = "/images/productphotos/small/$row->photoprimary" . "_475.jpg";
if (file_exists("$image"))
{}
else
{
echo "missing image for $row->title<br/>";
}

}
echo "$count</div>";
?> 
This just shows a load of "missing image" rows. Even tho most files are there.

Re: Checking if file exists not working... why?

Posted: Thu Mar 23, 2017 5:44 am
by pbs
Print the below line and check if you get its path correct.

Code: Select all

echo $image = "/images/productphotos/small/$row->photoprimary" . "_475.jpg";

Re: Checking if file exists not working... why?

Posted: Thu Mar 23, 2017 6:12 am
by Celauran
Use an absolute path instead.