Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

counting files in a directory with php 1

Status
Not open for further replies.

farley99

MIS
Feb 12, 2003
413
0
0
US
Hi,

How do i find out how many files are in my images directory?

$dirHandle = opendir("./images");
count files in $dirHandle;<-- what is this syntax for this?


Also, how do i subtract for ., .., and .htaccess, and .htacess232773

Is there was way to count only the files that dont begin with a dot?
 
<?
$count = 0;$count3 = 0;$count4 = 0;$count5 = 0;$count6 = 0;$count7 = 0;
if ($dir = opendir(&quot;images&quot;)) {
while (($file = readdir($dir)) !== false) {
$filename[$count] = $file;
$count++;
}
closedir($dir);
}
$count1 = count ($filename);
$count7 = 0;
for($z = 0; $z < $count1; $z++){
if(strstr($filename[$z],$Month2)){
$filenamemonth2[$count7] = $filename[$z];
$count7++;
}
}
$count20 = count ($filenamemonth2);
// ******************************************
// ** **
// ** Beginning of HTML Code !!!!! **
// ** **
// ******************************************
echo &quot;<html>
<head>
<meta http-equiv=Content-Language content=en-us>
<meta name=GENERATOR content=Microsoft FrontPage 5.0>
<meta name=ProgId content=FrontPage.Editor.Document>
<meta http-equiv=Content-Type content=text/html; charset=windows-1252>
<title>New Page 1</title>
</head>
<body topmargin=0 leftmargin=0><table width=%100 border=0 align=center>&quot;;

if(!$submit){
echo&quot;<tr>

<td width=%100 align=center valign=top>
<br>
&nbsp;<form method=POST action=userstats.php>
<p>
Choose a Server<br>
<select size=1 name=Server>
<option value=jpg>jpg</option>
<option value=gif>gif</option>

</select></p>
<p><input type=submit value=submit name=submit><input type=reset value=Reset name=B2></p>
</form>
<p>&nbsp;</td>&quot;;
}else{
if($Server){
for($z = 0; $z < $count20; $z++){
if(strstr($filenamemonth2[$z],$Server)) {
$filenameans = $filenamemonth2[$z];

echo&quot;<tr>
<td align=center>
<a href=xls/$filenameans>$filenameans</a></td>
</tr>&quot;;
}
}
}


}

echo &quot;</table>&quot;;
?>

I had to remove some code but just as an example grab everything into array then search array for the file extensions gif jpg your choice and display them.

You can modify to count array object minus certain files etc..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top