PHP – Convert File system path to URL

More accurate way (including host port) would be to use this

function path2url($file, $Protocol="http://") {
    return $Protocol.$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'], '', $file);
}

Leave a Comment