file_exists() in PHP and file path
<p>I have a folder <code>uploads</code> in the root folder. There is another folder <code>A</code> in the root, and contains a PHP file. I have the following code in the PHP file:</p>

<pre><code>$imgpath = '/uploads/' . $filename;
echo '&lt;img src="' . $imgpath . '" /&gt;';
echo (file_exists($imgpath))?'true':'false';
</code></pre>

<p>It will show the image, so the file exists, but <code>file_exists</code> shows <code>false</code>.</p>

<p>If I change <code>'/uploads/'</code> to <code>'../uploads/'</code>, it will show the image and <code>file_exists</code> shows <code>true</code>. Even if there is no image, <code>file_exists</code> always shows <code>true</code>.</p>

<p>What is the problem?</p>

<p><strong>* Update *</strong></p>

<p>I tried <code>echo dirname(__FILE__);</code>. It shows <code>/....../A</code>, the <code>uploads</code> folder is located at <code>/....../uploads</code>. Moreover, I have another similar PHP file in folder <code>/....../m/A</code>. So I need some kind of universal path. How to get the root path, i.e., <code>/....../</code>?</p>

<p>I also tried <code>$_SERVER['DOCUMENT_ROOT']</code>, but the image cannot be shown, although the path is 100% correct.</p>
