[SOLVED] Re: [PHP] ftp_put()'ing a string ...
| From: | Jochem Maas | Date: | Fri, 14 Jul 2006 01:09:13 +0000 |
| Subject: | [SOLVED] Re: [PHP] ftp_put()'ing a string ... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-239452@lists.php.net to get a copy of this message | ||
I figured out how to ftp a string into a remote file using the ftp streams wrappers.
the code looks as follows (I leave out the definition of the [error logging] callback
PLFTPServerNotifier() the prototype requirements of which can be found in the manual):
<?php
$context = stream_context_create(array('ftp' => array('overwrite' =>
false)));
stream_context_set_params($context, array('notification' =>
'PLFTPServerNotifier'));
$retval = file_put_contents("ftp://{$ftp_user}:{$ftp_pass}@{$ftp_server}:21/{$filename}",
$xml, 0, $context);
?>
turns out my upload function is 3 lines long - pretty cool stuff this streams functionality :-)
Jochem Maas wrote:
> hi everyone,
>
> I was wondering if anyone knew how (if possible) I could take a string
> and ftp_put()/ftp_fput() that string directly onto the remote server as a file
> (without first saving the string to disk temporarily locally)
>
> I imagine that there is a way to create a stream that refers to the string
> in question but I can't get my head round the streams functionality...
>
> Obviously saving the string temporarily to disk locally is an easy option
> but I was kind of using the situation I have now to try and do something a
> little fancy and learn something about streams.
>
> anyone with idea/pointers?
>
> TIA,
> Jochem.
>