Hello all, I have an image located at http://my_ip/~website/image.jpg A script for image resizing uses the function file_exists() to verify the image location in the following way: if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/~website/image.jpg")) { echo 'Error: image does not exist'; } Code (markup): The script returns the error message although the image exists and shows up when browsing to its http:// address. My only guess is that the symbol "~" causes the problem because the function works just fine on a different server with different url. Any ideas on how to make it work? Thanks in advance.
The reason your having the problem is because your calling out the who URL up to the file your currently using. Since your script will be pulling images from 2 directories up and not from the base directory the following code should work: <?php // Check To See If The File Does Not Exist if (!file_exists("./~website/image.jpg")){ echo 'Error: image does not exist'; } ?> Code (markup): However should you decide later to allow the user to change the URL in a settings file it could look like this: <?php // This goes in your settings or config file... $path ="./folder/where/you/will/store/the/images/"; // Include your config file include ('config.php'); // Check To See If The File Does Not Exist if (!file_exists($path . "image.jpg")){ echo 'Error: image does not exist'; } ?> Code (markup):
Thanks for the reply fwbbetsy. I have solved the problem by using a different path. It turns out that $_SERVER['DOCUMENT_ROOT'] does not display the actual path on the server which is, in fact, different. Moreover, "/~website" is not an existing directory, but a temporary address that redirects to "/home/website/public_html"