Re: ftp_put()'ing a string ...

From: Date: Tue, 11 Jul 2006 19:28:46 +0000
Subject: Re: ftp_put()'ing a string ...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-239321@lists.php.net to get a copy of this message
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? I stumbled accross the following page while RTFMing: http://php.net/manual/en/wrappers.ftp.php very nice, it enabled me the come up wth the following to lines (nice and compact!): $context = stream_context_create(array('ftp' => array('overwrite' => true))); $retval = file_put_contents("ftp://{$ftp_user}:{$ftp_pass}@{$ftp_server}:21/{$filename}", $xml, LOCK_EX, $context); BUT this leaves me with the problem of determining what went wrong if the file_put_contents() call fails. did the connection fail? did the login fail? did the write/upload fail (and why)? using the std. ftp functions it's [obviously] alot easier to determine at which point the failure occured. can anyone confirm I'm on the right track by trying to set 'notification' [stream]context parameter? > > TIA, > Jochem. >

« previous php.general (#239321) next »