The file_exists() function can be used to check if a file exists using either an absolute path, such as "/home/fritz/images/pic.jpg" or a path which is relative to the path from which the function is called...
For example, your web server directory structure might look like this:
/usr/local/httpd/htdocs/ <-- .php files in here
/usr/local/httpd/htdocs/images/ <--.jpg files
Suppose you have a script called index.php in the htdocs/ directory which checks for a file called 'pic.jpg' in the htdocs/images/ directory.
if(!file_exists("images/pic.jpg")) {
// file pic.jpg 'doesn't exist' code goes here...
} else {
// file pic.jpg 'does exist' code goes here...
}
You could just as easily make the test using the 'full path' to the image, however, this not the path you want to use for things like generating HTML <img src="" /> tags:
if(file_exists("/usr/local/httpd/htdocs/images/pic.jpg")) {
// file 'does exist' code goes here...
}
Any clearer now?