Welcome to WebmasterWorld Guest from 54.226.133.245

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

If image exists?

     
5:08 pm on Apr 9, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 2, 2008
posts:99
votes: 0


Well I need to check and see if and image exists if it does post the image and if it doesn't say "No Image" but I can't seem to find a PHP code that actually works. And I've tested many to see if they work or not but I'm clueless at where I am now...

Can anyone help me here?

5:32 pm on Apr 9, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


where is the image?

a little more explanation would help if you don't mind

5:35 pm on Apr 9, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 2, 2008
posts:99
votes: 0


This is the code I'm using:

<?php
$filename = 'example.com/images/pokemon/normal/001.png';

if (file_exists($filename)) {
echo "File exists";
} else {
echo "No Image";
}
?>

The image is at the link if you got to it but for some reason it says that the image isn't there.

[edited by: jatar_k at 6:50 pm (utc) on April 9, 2008]
[edit reason] please use example.com [/edit]

5:39 pm on Apr 9, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 30, 2000
posts:497
votes: 0


try the path

$filename = 'home/username/....';

or if you php script is in a folder below your image try

$filename = 'images/....';

5:44 pm on Apr 9, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 2, 2008
posts:99
votes: 0


omg... Wow I totally forgot about that way but it worked. Thanks!
7:17 pm on Apr 9, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 4, 2004
posts:877
votes: 0


I use this for includes:

include($_SERVER['DOCUMENT_ROOT'] . '/somefolder/somefile.php');

Works regardless of where the script is located.

soooooooooo.........try:

$filename = ($_SERVER['DOCUMENT_ROOT'] . '/images/pokemon/normal/001.png');