2

I have a simple statement below:

if(file_exists('/images/alum/'.$profile['pic'])) 
  echo '/images/alum/'.$profile['pic']; 
  else echo '/images/user_default.jpg';

The file is there but it's always going to the default image. What have I got wrong?

2
  • 1
    Are you sure your path is correct? Try ./images/alum/... Commented Jul 11, 2011 at 14:24
  • I would advise to do some reading about relative and absolute paths - both file paths (path of file that resides on filesystem) and URL paths (address that is being used with <a href=''></a> and other HTML tags). After reading about it, you should understand and be able to tell when (and why) to use ./images/, images/ or /images/. Commented Jul 11, 2011 at 14:40

4 Answers 4

1

You are saying on the server that the file at the root of the file system exists. You will have to probably add some . or ..

Sign up to request clarification or add additional context in comments.

Comments

0

Try:

if(file_exists('./images/alum/'.$profile['pic']))
 echo '/images/alum/'.$profile['pic']; 
 else echo '/images/user_default.jpg';

i.e. changing the "/images" to "./images" but only in the file_exists call.

Comments

0

Change it to this.

if(file_exists('./images/alum/'.$profile['pic'])) 
    echo './images/alum/'.$profile['pic']; 
else 
    echo './images/user_default.jpg';

Comments

0

make sure that $profile['pic'] has valid file name, contraction with path is valid, and current directory with parth point to file...

temporary negate condition to see file from profile...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.