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.
UPDATE
if (move_uploaded_file($_SESSION['item'][$i], $path))
{
$link = 'image/'.basename($_SESSION['item'][$i]);
echo "<td><img src='" . $link . "' /></td>";
}
This modification doesn’t show any letter. It seems that if block doesn’t execute.
Well why are you using
globalin the first place? Its not apparent from the snippet you provided as there is no reason to use it in this code alone.If its in a function pass
$urlas an argument… if its something else then we will need the details of usage.In regards to Col. Shrapnel’s answer if you omit the first
/youll get a link relative to the page accessed. Which as far as i can tell is what youre after:$link = 'image/'.basename($_SESSION['item'][$i]);