Jump to content

get Directory/File info


tensuke

Recommended Posts

Hey,I'm new to PHP so I'm still learning,but I have a question:
How do you get the number of files in a certain directory and store that into a variable?

And also,what would be the correct way display that variable's data?

Thanks for any help. ^_^
Link to comment
Share on other sites

Check the manual:

[a href=\"http://www.php.net/dir\" target=\"_blank\"]http://www.php.net/dir[/a]

There is a lot of good info there. Especially the user comments at the bottom.

There are a couple of functions there that will return an array with all the file names and subdirectory names in an array that you can then do a count on to get the number of files in the directory.

To display the value of nearly any variable, you can use either echo or print.

[a href=\"http://www.php.net/echo\" target=\"_blank\"]http://www.php.net/echo[/a]
[a href=\"http://www.php.net/print\" target=\"_blank\"]http://www.php.net/print[/a]

For arrays, use the print_r function:

[a href=\"http://www.php.net/print_r\" target=\"_blank\"]http://www.php.net/print_r[/a]
Link to comment
Share on other sites

Thanks for the info,that helped. :D

EDIT:
Howdy,
I'm using
[code]
<?php
$dir = "/ipbfree";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
   $ipbfree[] = $filename;
}

echo count($ipbfree);
?>
[/code]
to scan the files in the directory ipbfree.Ipbfree is in the same folder as the index.html that is running the script.
But everytime I try to fix it,it doesn't display anything.The number is between [ ],and so it just shoes [].
I am using PHP 4.3.11.Any ideas?
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.