Manjiri Parab Manjiri Parab - 18 days ago 6
PHP Question

echoing image tag in php using path

<?php

$dir= 'C:\xampp\htdocs\img';

echo "<img src='".$dir."\america.jpg' alt='icon'>";

?>


I just written this code for test and I couldn't get able to display image on browser need help urgently. thanks in advance

Answer

The path you are using is not correct, try this:

$path = '/img/';
$imgName = 'america.jpg';
echo '<img src="'. $path.$imgName .'" alt="icon">';
// If img folder is present in the same directory

or

$path = '../img/';
$imgName = 'america.jpg';
echo '<img src="'. $path.$imgName .'" alt="icon">';
// If img folder is present one directory upwards from current directory
Comments