I have been playing around with directory reading for accessing image galleries and everything works fine as long as the folder holding the images is on the same server as the php.

I have been using :

$dir = dir("images");

to retrieve the directory

But...

Is it possible to access a directory on a different server using a "http://example.co.uk/images" type reference? I would like to expand what I have written to read in the images I have on different webspace. Everytime I try and use such a reference I get a null return.

    Wouldn't that be nice if anyone could simply just read through some random webserver's directory?

    http://www.php.net/manual/en/function.opendir.php

    As of PHP 4.3.0 path can also be any URL which supports directory listing, however only the file:// URL wrapper supports this in PHP 4.3. As of PHP 5.0.0, support for the [url]ftp://[/url] URL wrapper is included as well.

      Thanks for the reply, great sarcasm 😉

        9 days later

        Hello,
        I guess I'm a noob because I don't understand what it means by:

        "As of PHP 4.3.0 path can also be any URL which supports directory listing, however only the file:// URL wrapper supports this in PHP 4.3"

        I have a website with the permissions setup to allow directory listing, and I'm running a script on another server but I cannot open the remote directory using:

        $dir='http://www.mywebpage/new/';

        if($dirname = opendir("$dir"))
        {
        echo "Directory was opened!";
        }
        else
        echo "Can't open $dir";

        Any advice? I just want READ only to these files.

        Thanks!

          You will probably never be allowed to do directory listing through a http URL. file:// is local files.

            Write a Reply...