Jump to content

Scanning a Directory


lpxxfaintxx

Recommended Posts

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?
Link to comment
Share on other sites

Or

[code]<?php
foreach (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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.