Forum Moderators: coopster
I have an image host, and I did like a code so that I can have a counter somewhere of how many images hosted...
(So it counts the folder all uploaded pictures are in)
I've googled it ofcause, but I either am using the wrong keywords or it isn't ready on a easy-to-find spot----
Can anyone help?
<?
$dir = '/path/to/directory/';
$filecount = 0;
$d = dir($dir);
while ($f = $d->read()) {
if(($f!= ".") && ($f!= "..")) {
if(!is_dir($f)) $filecount++;
}
}
echo 'there are ',$filecount,' files in this folder';
?>
this is completely untested but it should be close, just assign the actual path of the directory you want to count the files in to the $dir var in the beginning instead of /path/to/directory/
I made an empty file, posted what you wrote:
<?
$dir = '\';
$filecount = 0;
$d = dir($dir);
while ($f = $d->read()) {
if(($f!= ".") && ($f!= "..")) {
if(!is_dir($f)) $filecount++;
}
}
echo 'there are ',$filecount,' files in this folder';
?>
and it says: Parse error: parse error, unexpected T_STRING in /home2/clickspa/public_html/jpnupload/testing.php on line 11
I actually got earlier(before you posted) someone to try help me and he wrote:
<?php$path = "\";
if ($handle = opendir($path))
{
while (false!== ($file = readdir($handle)))
{
if (!is_dir($path. $file))
{
$filecount++;
}
}
closedir($handle);echo ('Total Images Hosted');
echo ('.$filecount.');
}?>
and it said: Parse error: parse error, unexpected $ in /home2/clickspa/public_html/jpnupload/testing.php on line 32
Don't know if this can help? (And no, there does not exsist a line 32...)
All I know is that my server does accept php, its php5 and its a linux server...
Any help please? anyone?
BTW: that is what I want :)
(A code that tells how many files there is in a certain folder, but not counting subfolders.)
The problem with both of those pieces of code is your slash, it's going the wrong way.
$dir = '\';
or
$path = "\";
that means you are escaping the closing quote and causing the parse error. turn it around.
$dir = '/';
or
$path = "/";
that would be for the server root, I doubt that is the folder you want. If you are looking for the root of your site try this
$dir = '/home2/clickspa/public_html/';
I wrote it once again:
[php]
<?php $path = "/home2/clickspa/public_html/jpnupload/"; if ($handle = opendir($path)) { while (false!== ($file = readdir($handle))) { if (!is_dir($path. $file)) { $filecount++; } } closedir($handle); $filecount = $filecount - 4; echo "Total Images Hosted: ". $filecount; }?>
[/php]
How can I make sure it does not count the subfolders in that folder, plus the subfolders files?
or does it already do that?