Shamoon Shamoon - 1 year ago 85
PHP Question

How can I read the directory contents on a remote server with PHP?

I have a url,
and the
directory allows Directory Listings. How can I get the files in that directory with PHP?

Answer Source

Here is an example if you need to read the images over HTTP and the server is Apache:

$url = '';

$html = file_get_contents($url);

$count = preg_match_all('/<td><a href="([^"]+)">[^<]*<\/a><\/td>/i', $html, $files);

for ($i = 0; $i < $count; ++$i) {
    echo "File: " . $files[1][$i] . "<br />\n";


If it is the same server you are running your PHP on, you can use opendir() and readdir().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download