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 Quote Link to comment 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>"; } } } ?> Quote Link to comment 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 Quote Link to comment 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, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.