Jump to content
  • Advertisement
Sign in to follow this  
Hellfish

[web] PHP file_exists problem

This topic is 3716 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all! PHP Newb here,hoping you could help.. I've got the following code:
$FSFriendlyTitle = str_replace(':',':',$VMRow['Title']);

echo "<h2>".$VMRow['Title']." (Season ".$VMRow['SeasonReleased'].")</h2><hr />";
//echo "/Images/Posters/".$FSFriendlyTitle.".jpg";
if(file_exists("/Images/Posters/".$FSFriendlyTitle.".jpg"))
{
echo "<img src="/Images/Posters/".$FSFriendlyTitle.".jpg" alt="".$VMRow[" title="]."" />&lt;p /&gt;";
}
else
{
echo "<img src="/Images/Posters/Poster Missing.jpg" alt="".$VMRow[" title="]."" />&lt;br /&gt;";
}

which is supposed to display an image file if it exists and a predefined one if it doesn't. The problem is that it always displays the predefined file, unless I negate the result from file_exists (but then the code attempts to display images that doesn't exist too). Yes, the images exist(the path is correct too, if I paste the output path[by the commented echo] into the url it works) and I have have a near identical setup with a different set of images, which works.If you need more info, just ask. Anybody got any idea here? edit:added source tags.

Share this post


Link to post
Share on other sites
Advertisement
file_exists() works with the local file system, so you'll need to pass the local path, such as /var/www/html/images/foo.jpg.

Share this post


Link to post
Share on other sites
Fix found but I'm not sure why.. Apparently there were some problems with a symlink in the path ('/home/cmmdb/www/...' instead of '/home/cmmdb/public_html/...') but that doesn't explain why the (what was originally) near identical version below always worked. The Poster code started out as the below snipped with paths changed and one added row of str_replace..

echo "<h2>".$VTRow['Name']."</h2><p/>";
if(file_exists("/Images/Talents/".$VTRow['Name'].".jpg"))
{
echo "<img src='/Images/Talents/".$VTRow['Name'].".jpg' alt='".$VTRow['Name']."'/><p/>";
}
else
{
echo "<img src='/Images/Talents/Unknown.jpg' alt='".$VTRow['Name']."'/><p/>";
}



The finished,working,snippet:

$FSFriendlyTitle = str_replace(':','&#58;',$VMRow['Title']);
$FSFriendlyTitle = realpath('/home/cmmdb/public_html/Images/Posters/'.$FSFriendlyTitle.'.jpg');&#8201;

echo "<h2>".$VMRow['Title']." (Season ".$VMRow['SeasonReleased'].")</h2><hr/>";
if(file_exists($FSFriendlyTitle))
{
echo "<img src='/Images/Posters/".basename($FSFriendlyTitle)."' alt='".$VMRow['Title']."'/><p/>";
}
else
{
echo "<img src='/Images/Posters/Poster Missing.jpg' alt='".$VMRow['Title']."'/><br/>";
}


Note: If it says "str_replace(':',':'..." that's just the forum pouting because I replace ':' with '& #58;' without the space.

Thanks, KonForce for getting me on the right track! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!