1

私はPHPが初めてです。

私は 2 つの異なるホストを持っており、そのうちの 1 つの php ページに、もう 1 つのディレクトリ リストを表示させたいと考えています。同じホストで opendir() を使用する方法は知っていますが、それを使用して別のマシンにアクセスすることは可能ですか?

前もって感謝します

4

3 に答える 3

7

試す:

<?php

$dir = opendir('ftp://user:pass@domain.tld/path/to/dir/');

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

closedir($dir);

echo "<ul>\n$str</ul>";
于 2011-03-13T22:50:42.540 に答える
6

PHP のFTP 機能を使用して、サーバーにリモート接続し、ディレクトリ リストを取得できます。

// set up basic connection
$conn_id = ftp_connect('otherserver.example.com'); 

// login with username and password
$login_result = ftp_login($conn_id, 'username', 'password'); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
    echo "FTP connection has failed!";
    exit; 
}

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 

// check upload status
if (!$upload) { 
    echo "FTP upload has failed!";
} else {
    echo "Uploaded $source_file to $ftp_server as $destination_file";
}

// Retrieve directory listing
$files = ftp_nlist($conn_id, '/remote_dir');

// close the FTP stream 
ftp_close($conn_id);
于 2011-03-13T22:49:20.977 に答える