I have a folder uploads in the root folder. There is another folder A in the root, and contains a PHP file. I have the following code in the PHP file:
$imgpath = '/uploads/' . $filename;
echo '<img src="' . $imgpath . '" />';
echo (file_exists($imgpath))?'true':'false';
It will show the image, so the file exists, but file_exists shows false.
If I change '/uploads/' to '../uploads/', it will show the image and file_exists shows true. Even if there is no image, file_exists always shows true.
What is the problem?
* Update *
I tried echo dirname(__FILE__);. It shows /....../A, the uploads folder is located at /....../uploads. Moreover, I have another similar PHP file in folder /....../m/A. So I need some kind of universal path. How to get the root path, i.e., /....../?
I also tried $_SERVER['DOCUMENT_ROOT'], but the image cannot be shown, although the path is 100% correct.