Hey.
I'm trying to open a dir under safe mode.
and i keep getting this error :

Fatal error: Uncaught exception 'RuntimeException' with message 'DirectoryIterator::__construct() [<a href='directoryiterator.--construct'>directoryiterator.--construct</a>]: Unable to access /home/mypath/mysite.com/public_html/path/to' in /home/mypath/mysite.com/public_html/site/loaddir.php:7 Stack trace: #0 /home/mypath/mysite.com/public_html/site/loaddir.php(7): DirectoryIterator->__construct('/home/mypath...') #1 {main} thrown in /home/mypath/mysite.co/public_html/site/loaddir.php on line 7

my question is :
is there a way i can open a dir under safe mode?
or maybe my code is wrong?

$root = $_SERVER["DOCUMENT_ROOT"];
$path = "/path/to"; 

$allowed = array('jpg','gif','bmp'); 
$iterator = new DirectoryIterator($root.$path);
foreach ($iterator as $fileinfo) {
    if ($fileinfo->isFile()) {
         $path = $fileinfo->getPathname();
         $filename = $fileinfo->getFilename(); 
         $info = pathinfo($filename); 
         $ext =  $info['extension']; 
         $filename_noext =  basename($filename,'.'.$ext);
         
         if (in_array($ext, $allowed)){
            echo "$filename_noext\n";
         }
    }
}

Help?

Recommended Answers

I don't know the framework you are using. What is it?
The PHP manual does not say that the dir class is not functional in safe mode. Try to use this class instead of your directory iterator.

Jump to Post

All 4 Replies

I don't know the framework you are using. What is it?
The PHP manual does not say that the dir class is not functional in safe mode. Try to use this class instead of your directory iterator.

I do not see any references to safe mode - neither in DirectoryIterator nor in the Dir class. Therefore I suggest that you try the Dir class.

Weird.
but it doesn't matter because with the Dir class it's the same problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.