How to get a URL from an image that was stored on the server


It must be very easy but I have no clue how to get the URL of an image from server.

Lets say I have domain named and the image has been stored in my


So, I want upload an image and save it through php script into my images folder and return the URL of that image back to browser like,

Is there any php function to get URL of a file?


After looking at answer I thought I should more clarify my self. I am really sorry for misunderstanding,

The help I wanted is to : what if the domain name isn't static I mean you can download and attach my image uploader plugin to your website but now it should dynamically get domain name and http path to your image.

Since i don't have your plugin, i don't know the flow of your code. My guess below, hopefully, you can modify it according to your code.

Suppose i download your plugin to my website and upload an image using it. You can get the image path like this:


$relative_path = $upload_path . DS . $image_name;

$path = str_replace( $_SERVER['DOCUMENT_ROOT'], $_SERVER['SERVER_NAME']
                                                            , $relative_path );

$path = 'http://' . $path; // this is where image is uploaded

Note: This assumes that the upload directory is within the webroot.

Hopefully, this will work.