note 44110 added to ref.ftp

From: Date: Thu, 15 Jul 2004 11:38:56 +0000
Subject: note 44110 added to ref.ftp
Groups: php.notes 
Request: Send a blank email to php-notes+get-73286@lists.php.net to get a copy of this message
If you prefer a OO-approach to the FTP-functions, you can use this snippet of code (PHP5 only! and does add some overhead). It's just a "start-up", extend/improve as you wish... You can pass all ftp_* functions to your object and stripping ftp_ of the function name. Plus, you don't have to pass the ftp-resource as the first argument. For example: <?php ftp_delete($ftp, $file); // Where $ftp is your ftp-resource ?> Can become: <?php $ftp->delete($file); // Where $ftp is your FTP-object ?> Code: <?php class FTP { private $ftp; /* public Void __construct(): Constructor */ public function __construct($host, $port = 21, $timeout = 90) { $this->ftp = ftp_connect($host, $port, $timeout); } /* public Void __destruct(): Destructor */ public function __destruct() { @ftp_close($this->ftp); } /* public Mixed __call(): Re-route all function calls to the PHP-functions */ public function __call($function, $arguments) { // Prepend the ftp resource to the arguments array array_unshift($arguments, $this->ftp); // Call the PHP function return call_user_func_array('ftp_' . $function, $arguments); } } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.ftp.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44110 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44110&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44110&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73286) next »