jpg bmp png扩展GET from image对于URL PHP mysql

时间:2011-07-24 12:28:52

标签: php mysql

我如何解决此问题以从图像文件夹中获取完整图像名称

<img style="margin:10 12 12 10px" border=0 src="<?php echo $siteurl."/wallpapers/thumbs/".$show_wallpaper["wallname"]."_".$show_wallpaper["wallpaperid"].".jpg"; ?>">

“JPG”  不仅仅是.jpg还可以回显.png或.bmp等(如果在图像文件夹中可用)

1 个答案:

答案 0 :(得分:1)

不太清楚你的意思,但是这样的话? 它将数组中的所有扩展放在文件路径的前面,如果存在,则输出图像。

$extensions_to_check = array('jpg','png','gif','jpeg');
$dir = '/path/to/dir/';
$file_name = 'wallpaper_something';

foreach($extensions_to_check as $ext) {
   $path = $dir . $file_name . $ext;
   if (file_exists($path)) {
      echo('<img src=\'' . $path . '\' />');
   }
}
相关问题