Lorenz Meyer
Lorenz Meyer

Reputation: 19895

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. 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.

Upvotes: 0

Views: 376

Answers (1)

Marek
Marek

Reputation: 7433

It's possible using wrappers:

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

Upvotes: 1

Related Questions