Tuesday, 1 October 2013

Browser will not display images - PHP

Browser will not display images - PHP

It would be great if someone could help me figure out why the browser
cannot load the images (error 404). The code works, and the image source
is correct, but I cannot figure out what is wrong. (using localhost)
<?php
$dir = '/home/user/Pictures';
$file_display = array('jpg', 'jpeg', 'png', 'gif');
if (file_exists($dir) == false) {
echo 'Directory \'', $dir, '\' not found!';
} else {
$dir_contents = scandir($dir);
foreach ($dir_contents as $file) {
$file_type = strtolower(end(explode('.', $file)));
if ($file !== '.' && $file !== '..' && in_array($file_type,
$file_display) == true)
{
echo '<img src="', $dir, '/', $file, '" alt="', $file, '" />';
}
}
}
?>

No comments:

Post a Comment