Welcome to WebmasterWorld Guest from 54.226.189.112

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

If image exists?

     

PokeTech

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

5+ Year Member



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?

jatar_k

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

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



where is the image?

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

PokeTech

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

5+ Year Member



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]

maccas

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

10+ Year Member



try the path

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

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

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

PokeTech

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

5+ Year Member



omg... Wow I totally forgot about that way but it worked. Thanks!

thecoalman

7:17 pm on Apr 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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');

 

Featured Threads

Hot Threads This Week

Hot Threads This Month