homepage Welcome to WebmasterWorld Guest from 54.237.213.31
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
If image exists?
PokeTech

5+ Year Member



 
Msg#: 3622818 posted 5:08 pm on Apr 9, 2008 (gmt 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?

 

jatar_k

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



 
Msg#: 3622818 posted 5:32 pm on Apr 9, 2008 (gmt 0)

where is the image?

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

PokeTech

5+ Year Member



 
Msg#: 3622818 posted 5:35 pm on Apr 9, 2008 (gmt 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]

maccas

10+ Year Member



 
Msg#: 3622818 posted 5:39 pm on Apr 9, 2008 (gmt 0)

try the path

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

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

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

PokeTech

5+ Year Member



 
Msg#: 3622818 posted 5:44 pm on Apr 9, 2008 (gmt 0)

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

thecoalman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3622818 posted 7:17 pm on Apr 9, 2008 (gmt 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');

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved