简体   繁体   English

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

[英]Send a variable's content to a file through FTP

I would like to create a file on a FTP server from a variable's content. 我想根据变量的内容在FTP服务器上创建文件。 Is this possible without writing the data to a file locally first ? 是否可以在不先将数据写入本地文件的情况下进行?

This is what I can do: 这是我可以做的:

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

But I would like to send $file_contents without saving it first to a file. 但是我想发送$file_contents而不先保存到文件中。

可以使用包装器:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM