我的 Web 服务器在一台服务器上运行,而数据获取在另一台服务器上运行。我的代码将尝试复制一个远程文件并将其存储在我的本地路径中。例如,远程位置是 /home/testUser/remoteData.xml。我知道服务器 IP 地址和主机名。如何构造路径以填写remotePath?
#remotePath is the path to the file on the network
public function __construct()
{
$this->localPath="currentData.xml";
$this->remotePath="a remote path";
}
#this will attempt to make a copy from that network file and store it locally
private function fetchServer()
{
if (!(file_exists($this->remotePath)) || (time() - filectime($this->remotePath)) >= 1200)
return false;
else
{ $success = copy($this->remotePath, $this->localPath);
if($success)
return true;
else
return false;
}
}
非常感谢你!