>uploads文件夹有不同类型的图像。我只想在网页上显示.gif图像。为什么不显示图像(请参阅输出屏幕截图)?
$dir = "uploads";
$allowedExts = array('jpg', 'jpeg', 'png', 'gif');
if( file_exists($dir) == false ){
echo 'Directory '''. $dir . ''' not found!';
}
else{
//$dir_contents = scandir( $dir );
$dir_contents = glob( $dir. "/*.gif" );
foreach( $dir_contents as $file ){
$exp_array = explode('.', strtolower($file));
$extension = end($exp_array);
if( in_array($extension, $allowedExts) ){
echo '<img src="'. $dir. '/'. $file. '" alt="'. $file. '" width="250" height="190" />';
}
}
}
截图
您只需替换代码中的以下代码:
if( in_array($extension, $allowedExts) ){
echo '<img src="'.$file. '" alt="'. $file. '" width="250" height="190" />';
}