私はPHPが初めてです。
私は 2 つの異なるホストを持っており、そのうちの 1 つの php ページに、もう 1 つのディレクトリ リストを表示させたいと考えています。同じホストで opendir() を使用する方法は知っていますが、それを使用して別のマシンにアクセスすることは可能ですか?
前もって感謝します
試す:
<?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>";
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);