Checking if file exists not working... why?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Checking if file exists not working... why?

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

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

Post 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";
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

Use an absolute path instead.
Post Reply