dongzongzi0379 2014-12-03 09:09
浏览 35

从文件夹中查找第一张图片

I am using below code successfully to find the first image from a folder and display it. The problem I have is that the client has uploaded images with a mixture of uppercase and lowercase .jpg extensions on the images. Can i adjust my code to allow for both uppercase and lowercase .jpg extensions, as it only likes lower case?

$search_dir = "properties/".$row['Reference_No'];
    $images = glob("$search_dir/*.jpg");
    sort($images);

    // Image selection and display:

    //display first image
    if (count($images) > 0) { // make sure at least one image exists
        $img = $images[0]; // first image
        echo "<img src='../../$img' width='320' height='200' border='0' /> ";
    } else {
        // possibly display a placeholder image?
    }
  • 写回答

2条回答 默认 最新

  • dongwa3808 2014-12-03 09:16
    关注

    You could merge your glob arrays

    $images = array_merge(glob("$search_dir/*.jpg"),glob("$search_dir/*.JPG"));
    

    As a side note; if you're handling the uploading of files, it might be an idea to strtolower() them when storing, this way you wont have issues and "untidiness"

    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题