0

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?

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by EricIskhakov
0

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.

0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.