dongshijiao6890 2019-06-18 05:35 采纳率: 0%
浏览 203

如何根据文件名从公共目录检查我的目标文件的扩展名?

I have an employee folder in the public directory. A picture can be uploaded there with different extensions. The extension can be either small or capital letters.

example : A user can upload a file such as listed below:

 12345.JPG Or 12345.jpg Or 12345.PNG Or 12345.png

When I am going to show/view this uploaded image file according to an employee number, first I need to know the uploaded file's correct extension from the public directory.

I have tried to show using below one only for one extension but not for all.

<img class="profile-user-img img-fluid img-circle"
    src="{{ (file_exists(public_path('/hrm/employee/'.$employee->employee_no.'.JPG'))) ? asset('/hrm/employee/'.$employee->employee_no.'.JPG') : asset('/hrm/employee/'.$employee->employee_no.'.jpg') }}"
    alt="User profile picture">

Can someone please tell me how can I show the image name from the directory without knowing the uploaded file's extension for a specific employee number?

  • 写回答

2条回答 默认 最新

  • dounuogong0358 2019-06-18 05:56
    关注

    You can get the file extension using pathinfo() method as shown below,

    $filename = "12345";
    
    $files = glob("F:\FilePath\\$filename.*");
    
    if (count($files) > 0)
    foreach ($files as $file)
     {
        $info = pathinfo($file);
        echo $filename.".".$info["extension"];
     }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂