PHP readdir() and opendir() working locally but not working on live server

5k views Asked by At

I was getting below error so changed

opendir(http://test.myserv.com/Optfolder/upload/upload) 

[function.opendir]: failed to open dir: not implemented 

so changed to file_get_contents($dir)

But then in next I got this error

readdir(): supplied argument is not a valid Directory resource 

What should I do?

I use below code to read folder images is there any option for opendir and readdir so ic an use them for my purpose?

In $dir I get full path like http://testserv.com/optfolder/upload

$dir = opendir($dir);

    while ($file = readdir($dir)) { 
       if (preg_match("/.png/",$file) || preg_match("/.jpg/",$file) || preg_match("/.gif/",$file) ) { 
       $string[] = $file;
       }
    }
3

There are 3 answers

0
thatonefreeman On

You can't use opendir() on HTTP urls. You need to specify a relative directory path instead. See opendir

4
SamV On

opendir() cannot be used on a URL as it opens a directory relative to the filesystem. This is also a potential duplicate of Warning: open dir: not implemented.

readdir() is also exactly the same as opendir() in regards to how it locates directories.

Please take a look at the documentation http://php.net/manual/en/function.opendir.php to fully understand it.

0
Joe Salmi On

Try using this:

file_get_contents('http://testserv.com/optfolder/upload');