954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

open dir problem

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() [directoryiterator.--construct]: 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?

EricIskhakov
Light Poster
42 posts since Mar 2009
Reputation Points: 10
Solved Threads: 3
 

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.

smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 

I am not using a framework.
the iterator is in the manual btw : http://php.net/manual/en/class.directoryiterator.php

and the manual does say that in safe mode it checks if the UID is the same like desired Dir.

EricIskhakov
Light Poster
42 posts since Mar 2009
Reputation Points: 10
Solved Threads: 3
 

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.

smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 

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

EricIskhakov
Light Poster
42 posts since Mar 2009
Reputation Points: 10
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: