通过 FTP 将变量的内容发送到文件

Send a variable's content to a file through FTP

我想根据变量的内容在 FTP 服务器上创建一个文件。如果不先将数据写入本地文件,这可能吗?

这是我能做的:

$tmpfname = tempnam("/tmp", "FOO");
file_put_contents($tmpfname, $file_contents)
ftp_put($conn_id, $destination_file, $tmpfname, FTP_BINARY);
unlink($tmpfname);

但我想发送 $file_contents 而不先将其保存到文件中。

可以使用包装器:

ftp_put($conn_id, $destination_file, 'data://text/plain;base64,' . base64_encode($file_contents), FTP_BINARY);