Is there any way to get the names of files in a folder? For example, I have 3 files in this folder: index.html script.php thisname.php thisothername.php I want the script to grab the names of the files in the folder with it. Is there any way to do this?
There is readdir($handle); Take a look at the explanation on php.net/readdir to see the best way to implement it in your site.
glob is another one: $textFiles = glob("*.txt") PHP: would fill $textFiles with an array of files ending in *.txt its a pretty useful function...
scandir() is yet another alternative, for PHP 5. It opens a directory, creates a list of all files, and closes the directory. There's one minor difference between it and using readdir() (that I've noticed so far). Readdir() actually accesses each file while it reads through the directory, so it resets the last accessed time for the file. scandir() doesn't access the file, so the last access time remains unchanged. - Walkere
$dir = "folder"; $handle = opendir($dir); while($file = readdir($handle)) { if($file != "." && $file != "..") { print "<p>$file</p>"; } } closedir($handle); PHP: