PHP - opendir on another server

后端 未结 3 739

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 opend

3条回答
  •  生来不讨喜
    2020-12-20 08:39

    I was unable to get the FTP suggestions to work so I took a more unconventional route, basically it yanks the html from the "Index of" page and extracts the filenames.

    Index page:

    Index of /files

  • Parent Directory
  • 1.jpg
  • 2.jpg
  • Extraction code:

        $dir = "http://www.yoursite.com/files/";
        $contents = file_get_contents($dir);
        $lines = explode("\n", $contents);
        foreach($lines as $line) {
            if($line[1] == "l") { // matches the 
  • tag and skips 'Parent Directory' $line = preg_replace('/<[^<]+?>/', '', $line); // removes tags, curtousy of http://stackoverflow.com/users/154877/marcel echo trim($line) . "\n"; } }
提交回复
热议问题