Ölümcül hata: yakalanmamış özel durum 'RuntimeException'

3 Cevap

PHP sürüm 5.2.11 ile döner ...

Ölümcül hata: iletisiyle yakalanmamış istisna 'RuntimeException' DirectoryIterator :: __construct (/ home / test / test.com / wp-content / themes / Mytheme / images) [. DirectoryIterator - inşa]: failed to open dir: Böyle dosyası veya / home/test/test.com/testing123/wp-content/themes/mytheme/functions.php dizin ': 462 Yığın izleme: # 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 ...') / home/test/test.com/testing123 içerisinde 5 / home/test/test.com/testing123 / hattında 462 wp-content/themes/mytheme/functions.php

Fonksiyonu altında ...

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;

}

GÜNCELLEME: buldum burada sorun tema ana URL kapalı bir sanal dizini altında yüklü olmasıdır. Benim komut tema ana kök url kapalı yüklü olduğundan bekliyoruz ...

http://site.com/testing123/wp-content/themes/mytheme, örneğin, bu durumda teması monte edilmiştir

Ancak, ben bekliyorum bu: http://site.com/wp-content/themes/mytheme

VE SO ...

O bir sanal dizin altında yüklü olabileceğini dikkate almaz beri benim yol işlev başarısız olur.

Nasıl bu fonksiyonun benim beslenmesinde bu senaryo için hesap verebilir?

$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;

}

3 Cevap

Bir try-catch bloğu koyunuz?

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;

Sınıf var, ama görünüşe görüntüleri dizin değil:

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

Mesajı olmanın önemli bir parçasıdır:

failed to open dir: No such file or directory

Eğer varsa Veya, PHP ondan okumak için gerekli izinlere sahip değil.

Üçüncü satır sizi dizin bulunamadı edilemez söylüyorum gibi görünüyor:

dir açılamadı: Böyle bir dosya ya da dizin yok

Ben çağrılan komut yolunu kontrol edin ve uygun olduğunu ayarlamak istiyorsunuz