在PHP中获取服务器上的绝对路径

I want absolute path of the a file starting from

http://...../file.jpg. 

But instead m getting something like

\/home\/abc\/public_html\/def\\file.JPG

Also dont know the reason for "/" The code am using is

dirname(__FILE__)."\\file.jpg"

Any help please?

This should do it:

$path = substr( __FILE__, strlen( $_SERVER[ 'DOCUMENT_ROOT' ] ) );
$url = $_SERVER['SERVER_NAME'].$path;

This works with $_SERVER['SCRIPT_URI']. Just concatenate the result with your domain name:

$domain = 'http://www.example.com' . $_SERVER['SCRIPT_URI'];

$_SERVER Variables