Jump to content

Count files in a directory always returns 0


jcpeden

Recommended Posts

I'm trying to count the number of files in a directory on my local server. When I browse to the directory I can see this:

 

screen.jpg

 

Here is the code that I'm using:

 

$category = get_the_category();
$cat_slug = $category[0]->category_nicename;
$dir = 'http://localhost/badsexsucks/wp-content/themes/AskIt/images/gay/';

if (glob("$dir*.jpg") != false)
{
$filecount = count(glob("" .$dir. "*.jpg"));

echo $filecount;
}
else
{
echo 0;
}

 

For some reason, it always returns 0

 

I've tried both:

$dir = 'http://localhost/badsexsucks/wp-content/themes/AskIt/images/gay/';

$dir = '../images/gay/'

I've tried both:

$dir = 'http://localhost/badsexsucks/wp-content/themes/AskIt/images/gay/';

$dir = '../images/gay/'

 

So, if I can't use a web address with glob, should the relative link work? Here is an image to show you the file structure. The file running this function is entry.php and is located in includes.

 

structure.png

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.