I am currently creating an e-commerce website where I retrieve the vehicle details from the database and search for its image in a folder. I used the code below for searching the folder for the image, but it only show the name of the JPG file and not the image of it. Could anyone help to to determine how I could display the image of the vehicle
$imageName=$_POST['car'];
if ($handle = opendir('Images/$imageName')) {
$dir_array = array();
while (false !== ($file = readdir($handle))) {
if($file!="." && $file!=".."){
$dir_array[] = $file;
}
}
echo $dir_array[rand(0,count($dir_array)-1)];
closedir($handle);
}
You have to put html tags around the result. Try:
echo "<img src='PATH_TO_IMAGE/".$dir_array[rand(0,count($dir_array)-1)]."'>";where PATH_TO_IMAGE is the relative/absolute url address to your images folder
Ex
echo "<img src='/images/".$dir_array[rand(0,count($dir_array)-1)]."'>";