tmallen Posted January 14, 2008 Share Posted January 14, 2008 I'd like a script that will list all files in the present working directory (pwd) as links. How can this be done? I don't know much about using PHP to read local files. Is there something like the "ls" command to do this with PHP? Link to comment https://forums.phpfreaks.com/topic/85890-script-to-list-all-files-in-pwd-as-links/ Share on other sites More sharing options...
cooldude832 Posted January 14, 2008 Share Posted January 14, 2008 look into glob <?php $path = ""; $data = glob($path."/*"); print_r($data); ?> Link to comment https://forums.phpfreaks.com/topic/85890-script-to-list-all-files-in-pwd-as-links/#findComment-438521 Share on other sites More sharing options...
tmallen Posted January 14, 2008 Author Share Posted January 14, 2008 OK, cool, that works. I browsed the docs for glob(), but I can't figure out how to grab the name of the current directory. How can I track this down? Link to comment https://forums.phpfreaks.com/topic/85890-script-to-list-all-files-in-pwd-as-links/#findComment-438544 Share on other sites More sharing options...
tibberous Posted January 14, 2008 Share Posted January 14, 2008 glob, thats a new one. cool. Link to comment https://forums.phpfreaks.com/topic/85890-script-to-list-all-files-in-pwd-as-links/#findComment-438551 Share on other sites More sharing options...
tmallen Posted January 14, 2008 Author Share Posted January 14, 2008 I've noticed that glob() doesn't return my hidden files. However, the following method does. Is there an option to return hidden files with glob()? if ($handle = opendir('./')) { while (false !== ($file = readdir($handle))) { echo "<li><a href=\"$file\">$file</a></li>"; } } Link to comment https://forums.phpfreaks.com/topic/85890-script-to-list-all-files-in-pwd-as-links/#findComment-438556 Share on other sites More sharing options...
cooldude832 Posted January 14, 2008 Share Posted January 14, 2008 most likely because glob is matching files that names are viewable vs your system of retriving all files in a folder. Link to comment https://forums.phpfreaks.com/topic/85890-script-to-list-all-files-in-pwd-as-links/#findComment-438569 Share on other sites More sharing options...
tmallen Posted January 14, 2008 Author Share Posted January 14, 2008 Which is better? I think that this is certainly more readable: <?php echo "<ul>\n"; foreach ($file_list as $file) { echo " <li><a href=\"$file\">$file</a></li>\n"; } echo "</ul>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/85890-script-to-list-all-files-in-pwd-as-links/#findComment-438570 Share on other sites More sharing options...
tmallen Posted January 14, 2008 Author Share Posted January 14, 2008 Hold on, left out the most important part: <?php $file_list = glob("*"); echo "<ul>\n"; foreach ($file_list as $file) { echo " <li><a href=\"$file\">$file</a></li>\n"; } echo "</ul>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/85890-script-to-list-all-files-in-pwd-as-links/#findComment-438572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.