Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the PHP function glob() return files that do not match the wildcard?

Tags:

php

glob

In data2 directory, I have these files:

alt text

With the following code (running on Mac), I want to only get the files that end with .xls:

$file_names = glob('data2/*.xls');
foreach ($file_names as $file_name) {
    echo $file_name . '<br/>';
}

I would expect that this code would return one file 27template.xls, however, it also returns the files with TEMP in them and adds a .xls to them:

alt text

Added: also if I change smaller.xls to smaller.xlsx then it does NOT find it as expected, but if I change it to smaller.NNN it finds smaller.NNN.xls.

How can I use glob() to only get .xls files?

like image 632
Edward Tanguay Avatar asked Nov 05 '22 04:11

Edward Tanguay


1 Answers

I think it is because the extension you are looking at might be not the real one (hided by default on Finder). You can check the real extension by clicking on the file and click on "Get info". If you want to show the extensions of all file you have to follow the steps by the Apple documentation:

To show the extension for all files, choose Finder > Preferences and click Advanced, then select "Show all file extensions."

like image 97
Shoe Avatar answered Nov 14 '22 23:11

Shoe