Drezard Posted September 29, 2007 Share Posted September 29, 2007 Okay basically, how would i do a ls or dir command in php? So, I want to output to the user exactly what directories and files are in a certain file... What command or code could i use? Regards, Daniel Link to comment https://forums.phpfreaks.com/topic/71144-the-dir-or-ls-command/ Share on other sites More sharing options...
dingus Posted September 29, 2007 Share Posted September 29, 2007 hey daniel looks to my like you are in search of something like this <? if ($handle = opendir('.')) //put here your own folder e.g. opendir('/home') also it needs to be abolute { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "$file<br>"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/71144-the-dir-or-ls-command/#findComment-357785 Share on other sites More sharing options...
Drezard Posted September 29, 2007 Author Share Posted September 29, 2007 how would I filter it too display only folders? Daniel Link to comment https://forums.phpfreaks.com/topic/71144-the-dir-or-ls-command/#findComment-357797 Share on other sites More sharing options...
hemlata Posted September 29, 2007 Share Posted September 29, 2007 Hello, Modify your code with following code block to get the required results. <?php $tempPath = "img/"; if ($handle = opendir($tempPath)) { while (false !== ($file1 = readdir($handle))) { if ($file1 != "." && $file1 != "..") { if(is_dir($tempPath."/".$file1)) { echo $file1 . '<br>'; } } } closedir($handle); } ?> Hope this will solve your issues. Regards, Link to comment https://forums.phpfreaks.com/topic/71144-the-dir-or-ls-command/#findComment-357805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.