PHP - 另一台服务器上的 opendir [英] PHP - opendir on another server

查看:27
本文介绍了PHP - 另一台服务器上的 opendir的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 PHP 有点陌生.

I'm kinda new to PHP.

我有两个不同的主机,我希望其中一个中的 php 页面向我显示另一个的目录列表.我知道如何在同一主机上使用 opendir() 但是否可以使用它来访问另一台机器?

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?

提前致谢

推荐答案

您可以使用 PHP 的 FTP Capabilities 远程连接到服务器并获取目录列表:

You could use PHP's FTP Capabilities to remotely connect to the server and get a directory listing:

// 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);

这篇关于PHP - 另一台服务器上的 opendir的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆