要从 URL 检索数据,您有几个选项。您说您只希望内存中的数据直接推送到 FTP 主机。
一种方法(我发现使用最简单,但缺乏可靠性和错误处理)是file_get_contents()
例子:
$url = 'http://www.domain.com/csvfile';
$data = file_get_contents($url);
现在你有你的 csv 数据$data
,关于如何将它推送到 ftp 服务器。
同样,最简单的方法是使用上面 get 示例中使用的内置流包装器。(但请注意,这需要 PHP 4.3.0)
像这样简单地建立连接字符串。
$protocol = 'ftps';
$hostname = 'ftp.domain.com';
$username = 'user';
$password = 'password';
$directory = '/pub';
$filename = 'filename.csv';
$connectionString = sprintf("%s://%s:%s@%s%s/%s",
$protocol,$username,$hostname,
$password,$directory,
$filename);
file_put_contents($connectionString,$data);
看看ftp 包装器手册
如果这不起作用,还有其他选择。
您可以使用curl获取数据并使用FTP 扩展来推送它。