lpxxfaintxx Posted March 8, 2006 Share Posted March 8, 2006 How can you scan a directory and list all the files in it? I know its a pretty simple script, but I lost the tuts to it. Links/tuts/examples would be greatly appreciated.Thanks in advanced.edit: I have [code]<?php$dir = '/upload';$files1 = scandir($dir);print_r($files1);?> [/code]but it says "Fatal error: Call to undefined function: scandir() in /home/lpxxfain/public_html/scandir.php on line 11"Any ideas? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 8, 2006 Share Posted March 8, 2006 Look at the [a href=\"http://www.php.net/glob\" target=\"_blank\"]glob[/a]() function.Ken Quote Link to comment Share on other sites More sharing options...
lpxxfaintxx Posted March 8, 2006 Author Share Posted March 8, 2006 Or [code]<?phpforeach (glob("*.txt") as $filename) { echo "$filename size " . filesize($filename) . "\n";}?> [/code]When I run it, it comes out like [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]0.gif size 221 1.gif size 203 2.gif size 225 3.gif size 225 4.gif size 229 403.shtml size 1490 404.shtml size 1475 5.gif size 225 500.shtml size 1455 6.gif size 226 7.gif size 215 8.gif size 224 9.gif size 230 BagFullOfSh1t.zip size 22519 BagFullOfSh1t1.0.txt size 5 BagFullOfSh1t1.0.txt.zip size 34653 BagFullOfSh1t1.1.txt size 5 BagFullOfSh1t1.1.zip size 33512 BagFullOfSh1t11.txt size 33497 Fountains Of Wayne - Stacys Mom.mp3 size 4757017 Linkin Park - Hit The Floor.mp3 size 3940891 aboutus.php size 16665 animated.gif size 328841 clip.mp3 size 1342400 contact.php size 16665 db_mysql.inc size 10345 getfile.php size 321 index.php size 1141 intro.swf size 72788 labels.rdf size 2216 labels_1.rdf size 2216 members.php size 16665 noel.jpg size 5575 noel2.jpg size 6112 novell_login.zip size 15843 rules.php size 16665 scandir.php size 433 scandir.txt size 426 test.php size 1055 tournaments.php size 16665 update.zip size 33512 upload.php size 11348 xmas.mp3 size 4614815 zero.zip size 61470[/quote]Is there any way so that </br> can be included with every different file?edit: fixed. Thanks for your quick help! <3 Quote Link to comment Share on other sites More sharing options...
lpxxfaintxx Posted March 8, 2006 Author Share Posted March 8, 2006 Oops, 1 more question. Is there any way to list how many files there are? Like, "There are 426 Files in this directory" Quote Link to comment Share on other sites More sharing options...
lpxxfaintxx Posted March 8, 2006 Author Share Posted March 8, 2006 ^ is that even possible? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 9, 2006 Share Posted March 9, 2006 Yes, it's possible:[code]<?php$dir_tmp = glob('*.txt');foreach ($dir_tmp as $filename) { echo $filename . ' size ' . filesize($filename) . "<br />\n";}echo 'There are ' . count($dir_tmp) . ' files in this directory<br>';?>[/code]Ken 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.