如果有人可以帮我弄清楚为什么浏览器无法加载图像会很棒(错误404).代码工作,图像源是正确的,但我无法弄清楚出了什么问题.(使用localhost)
$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, '" />';
}
}
}
Run Code Online (Sandbox Code Playgroud) php ×1