Question

I am using the following code to display the files in descending order of date. But When I upload any file without extension its not visible because of glob, is there any way to show the hidden files?

Code:

<?php
$dir = "/opt/lampp/htdocs/jquery"; 
chdir($dir); 
array_multisort(array_map('filemtime', ($files = glob("*.*"))), SORT_DESC, $files); 
foreach($files as $filename) 
{ 
    echo "<li>".$filename."</li>";  
}  
?>
Was it helpful?

Solution

@bodi0 gave you the code for ONLY items with no dots, you might be looking for

...glob("*")

to get all files. Then, you will need to remove "." and ".."

OTHER TIPS

This is impossible with inclusive only glob (python), the answerers (is that a word), misunderstood your question.

/* gets all files/folders and returns folders with no "/" at the end, /*/ gets only folders and adds the "/" at the end, but for files with NO extension ie path/foo (NO DOT) it is not straightforward to separate the files from the folders with glob.

It is possible, of course, just pass this regex pattern to the glob():

glob("([^\.])");

The pattern ([^\.]) means every file name, which does not have a dot in it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top