tags:

views:

252

answers:

3

PHP version is 5.2.11 returns...

Fatal error: Uncaught exception 'RuntimeException' with message 'DirectoryIterator::__construct(/home/test/test.com/wp-content/themes/mytheme/images) [directoryiterator.--construct]: failed to open dir: No such file or directory' in /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php:462 Stack trace: #0 /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php(462): DirectoryIterator->__construct('/home/test/wie...') #1 /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php(31): get_dirs('/home/test/wie...') #2 /home/test/test.com/testing123/wp-settings.php(717): include('/home/test/wie...') #3 /home/test/test.com/testing123/wp-config.php(76): require_once('/home/test/wie...') #4 /home/test/test.com/testing123/wp-load.php(30): require_once('/home/test/wie...') #5 /home/test/test.com/testing123 in /home/test/test.com/testing123/wp-content/themes/mytheme/functions.php on line 462

Function is below...

function get_dirs($path = '.') {
$dirs = array();
foreach (new DirectoryIterator($path) as $file) {  //this is line 462
    if ($file->isDir() && !$file->isDot()) {
        $dirs[] = $file->getFilename();
    }
}

return $dirs;

}

UPDATE: The problem here I've found is that the theme was installed under a virtual directory off the main URL. My scripts are expecting that the theme is installed off the main root url...

example, the theme in this case was installed at: http://site.com/testing123/wp-content/themes/mytheme

However, I'm expecting this: http://site.com/wp-content/themes/mytheme

AND SO...

My path function fails since it does not take into consideration that it could be installed under a virtual directory.

How could i account for this scenario in my feeding of this function?

$mydir = get_dirs($_SERVER['DOCUMENT_ROOT'].'/wp-content/themes/mytheme/images');

function get_dirs($path = '.') {
$dirs = array();
foreach (new DirectoryIterator($path) as $file) {
    if ($file->isDir() && !$file->isDot()) {
        $dirs[] = $file->getFilename();
    }
}

return $dirs;

}

+1  A: 

Enclose it in a try-catch block?

function get_dirs($path = '.') {
  $dirs = array();
  try{
    foreach (new DirectoryIterator($path) as $file) {  //this is line 462
    if ($file->isDir() && !$file->isDot()) {
      $dirs[] = $file->getFilename();
     }
   }
 } catch(Exception $e) {
   //log exception or process silently
   //just for test
   echo $e;
 }

 return $dirs;
Maurice Kherlakian
Thanks Maurice, I believe this is perhaps the best option. I've updated my question as I've found more info on what's causing the error. Its in fact due to the unexpected location under the virtual directory.My code...$mydir = get_dirs($_SERVER['DOCUMENT_ROOT'].'/wp-content/themes/mytheme/images');DOES NOT ACCOUNT FOR THE "testing123" subdirectory.
Scott B
+1  A: 

The class is there, but apparently your images directory is not:

/home/test/test.com/wp-content/themes/mytheme/images

The key part of the message being:

failed to open dir: No such file or directory

Or, if it is there, PHP doesn't have permissions to read from it.

Eric Petroelje
A: 

It looks like the third line is telling you that the directory cannot be found:

failed to open dir: No such file or directory

I would check your path from the script being called and adjust that appropriately

bkildow