Open remote directory for reading

I’m trying to open a remote directory of images and loop through them in php… but I get this:

Warning: opendir( [function.opendir]: failed to open dir: not implemented in /path/to/file.php on line 175

I assumed it might be related to php.ini, and confirmed the setting:

allow_url_fopen = On

I also confirmed that opendir works locally.

The source files are just plain images that are accessible in the browser.

Any ideas on the problem?

Why not using FTP connect? Though i have not worked like that and even used, you can try with FTP connect functions in PHP.

no, because using ftp will slow the page down, and this is a file that is accessed thousands of time a day.

So wheeler, are you sure that it is possible to open the remote directory with opendir() function? Or you have worked with opendir() to open remote directory before? I heard but read anywhere yet it is not possible to open remote file/directory opendir() function.

I can’t seem to get a clear answer either, i’ve been looking for over an hour but can’t find anything much…

some people seem to say u have to use fopen() and regex to read the remote folder contents and filter them, because opendir() doesn’t work remotely - while other sources say you can open remote folders…

When I give some tries i got the errors like this:

  1. $dir = “”;

Warning: opendir( [function.opendir]: failed to open dir: not implemented in C:\\xampp\\htdocs\	est\\ftp.php on line 3

  1. $dir = “http:://”;

Warning: opendir( [function.opendir]: failed to open dir: FTP server reports 2a‘| in C:\\xampp\\htdocs\	est\\ftp.php on line 3

And somewhere in the internet i had found this line before

..... and as you seem to be aware, opendir() works on DIRECTORIES, not URLs. And opendir() only works in local directories of code running system not remove.

No opendir cannot because a remote server does not send a directory listing.

If the server sends an HTML directory listing then you can process that.
Or better yet use FTP, and not FTP is not slow when it comes to files on remote systems FTP was designed for it.

opendir works only with FTP resources, no http. Your options are either to parse html directory listing with regexps or to use ftp.

Do you mean like this stereofrog?

$dir = "";
if ($dh = opendir($dir)) {
	while (($file = readdir($dh)) !== false) {
		echo "filename: $file : filetype: " . filetype($dir . $file) . "\

But this gave me this error:

Warning: opendir( [function.opendir]: failed to open dir: FTP server reports 2a‘| in C:\\xampp\\htdocs\	est\\ftp.php on line 3

Honestly, I’ve never used opendir with ftp, and I don’t see any need to, since [fphp]ftp_nlist[/fphp] works just fine.

Ahh! I know with FTP functions we can do it that’s why i had told wheeler to do this with FTP in my first reply post here.

thanks for responses, im still skeptical that ftp is a good idea… how could opening up dozens (if not tonnes) of simultaneous ftp connections 24/7 be a speed efficient process compared to http?

I have complete control of both servers, they are both dedicated and sitting side by side… the images are split from the main server for added speed.

I guess it does make sense that opendir() doesn’t work the same remotely as it does locally…


a 3rd option would be to store all the file names in the database (half a million and counting) and simply hotlink them in. Of the three options, this is probably the best one as far as I can see. I suppose this also presents further benefits such as storing more file information, but also adds a new layer of complexity.