Ben
Ben

Reputation: 777

Fatal error: Class Filesystemiterator not found

I'm getting that error when trying to use this code

<?php
$fi = new FilesystemIterator("image/Images", FilesystemIterator::SKIP_DOTS);
$count = iterator_count($fi);
if ($count-2<0){
$i = 0;
}
else{
$i = $count -2;
}
echo $i;
?>

Is there an alternative to what I have written? I think it might be something to do with my version of php on my webhost... I don't want to change the version though, so a work around would be helpful.

Upvotes: 2

Views: 1517

Answers (2)

Thamaraiselvam
Thamaraiselvam

Reputation: 7080

As @Mark Baker mentioned on comment -

FileSystemIterator requires PHP >= 5.3.0

and my PHP version is lower than 5.3.0 , I upgraded that fixed my problem.

Either you could check phpversion or class_exists before calling FileSystemIterator

Upvotes: 0

Rizier123
Rizier123

Reputation: 59701

Just use glob() and count() like this:

$fi = glob("image/Images/*.*");
$count = count($fi);

Upvotes: 3

Related Questions