Creating an URL without global variables
- by dygi
I have a code like this below, which gives me a $link that equals to: http://mydomain.com/image/photo.JPG
if (!empty($_SESSION['item'][$i]))
{
$path = dirname(__FILE__).'/image/'.basename($_SESSION['item'][$i]);
if (move_uploaded_file($_SESSION['item'][$i], $path))
global $url;
if ( $url )
{
$link = $url.'/image/'.basename($_SESSION['item'][$i]);
echo "<td><img src='" . $link . "' width='50' height='50' /></td>";
}
}
I wonder, how should I properly ommit using global variable here to achieve the same result.