1

I am getting this error while using the RecursiveDirectoryIterator.

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(public/user_/,public/user_/): The system cannot find the path specified. (code: 3)' in D:\xam\htdocs\s\upload.php:101 Stack trace: #0 D:\xam\htdocs\s\upload.php(101): RecursiveDirectoryIterator->__construct('public/user_/') #1 D:\xam\htdocs\s\upload.php(138): dirSize('public/user_/') #2 {main} thrown in D:\xam\htdocs\s\upload.php on line 101

Here is the code i am using.

function dirSize($directory) {
    $size = 0;
    foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
        $size+=$file->getSize();
    }
    return $size;
}

Please help!!!

1 Answers1

-1

There is a limited context here to see what is going wrong. However it would appear that your giving a directory to D:\xam\htdocs\s\upload.php that is not valid to start the iteration and find the size.

The try/catch option would stop it from throwing an error and failing

function dirSize($directory) {
  $size = 0;
  try {
    foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
      $size += $file->getSize();
    }
  } catch(Exception $e) {
    echo "Error: " . $e;
    echo "On: " . $directory;
  }
  return $size;
}
Shadoath
  • 720
  • 1
  • 15
  • 31