note 90313 added to context.ftp

From: Date: Thu, 16 Apr 2009 01:19:02 +0000
Subject: note 90313 added to context.ftp
Groups: php.notes 
Request: Send a blank email to php-notes+get-153366@lists.php.net to get a copy of this message
This is an example of how to allow fopen() to overwrite a file on an FTP site. If the stream context is not modified, an error will occur: "...failed to open stream: Remote file already exists and overwrite context option not specified...". <?php // The path to the FTP file, including login arguments $ftp_path = 'ftp://username:password@example.com/example.txt'; // Allows overwriting of existing files on the remote FTP server $stream_options = array('ftp' => array('overwrite' => true)); // Creates a stream context resource with the defined options $stream_context = stream_context_create($stream_options); // Opens the file for writing and truncates it to zero length if ($fh = fopen($ftp_path, 'w', 0, $stream_context)) { // Writes contents to the file fputs($fh, 'example contents'); // Closes the file handle fclose($fh); } else { die('Could not open file.'); } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 70.193.80.182 ---- Manual Page -- http://www.php.net/manual/en/context.ftp.php Edit -- https://master.php.net/note/edit/90313 Del: integrated -- https://master.php.net/note/delete/90313/integrated Del: useless -- https://master.php.net/note/delete/90313/useless Del: bad code -- https://master.php.net/note/delete/90313/bad+code Del: spam -- https://master.php.net/note/delete/90313/spam Del: non-english -- https://master.php.net/note/delete/90313/non-english Del: in docs -- https://master.php.net/note/delete/90313/in+docs Del: other reasons-- https://master.php.net/note/delete/90313 Reject -- https://master.php.net/note/reject/90313 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#153366) next »