tensuke Posted March 21, 2006 Share Posted March 21, 2006 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. ^_^ Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 22, 2006 Share Posted March 22, 2006 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] Quote Link to comment Share on other sites More sharing options...
tensuke Posted March 22, 2006 Author Share Posted March 22, 2006 Thanks for the info,that helped. :DEDIT: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? Quote Link to comment Share on other sites More sharing options...
tensuke Posted March 22, 2006 Author Share Posted March 22, 2006 Anyone? Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted March 23, 2006 Share Posted March 23, 2006 php cannot be run in an html file, rename it to index.php Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 23, 2006 Share Posted March 23, 2006 Look at the [a href=\"http://www.php.net/glob\" target=\"_blank\"]glob[/a]() function. It's much easier to use.[code]<?php$ipbfree = glob('/ipbfree');echo count($ipbfree);?>[/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.