PHP - opendir on another server

Auxiliary picture Auxiliary · Mar 13, 2011 · Viewed 13.5k times · Source

I'm kinda new to PHP.

I've got two different hosts and I want my php page in one of them to show me a directory listing of the other. I know how to work with opendir() on the same host but is it possible to use it to get access to another machine?

Thanks in advance

Answer

Marcel picture Marcel · Mar 13, 2011

Try:

<?php

$dir = opendir('ftp://user:[email protected]/path/to/dir/');

while (($file = readdir($dir)) !== false) {
    if ($file[0] != ".") $str .= "\t<li>$file</li>\n";
}

closedir($dir);

echo "<ul>\n$str</ul>";