note 105868 added to book.ftp

From: Date: Wed, 21 Sep 2011 16:15:45 +0000
Subject: note 105868 added to book.ftp
Groups: php.notes 
Request: Send a blank email to php-notes+get-183327@lists.php.net to get a copy of this message
For those who dont want to deal with handling the connection once created, here is a simple class that allows you to call any ftp function as if it were an extended method. It automatically puts the ftp connection into the first argument slot (as all ftp functions require). This code is php 5.3+ <?php class ftp{ public $conn; public function __construct($url){ $this->conn = ftp_connect($url); } public function __call($func,$a){ if(strstr($func,'ftp_') !== false && function_exists($func)){ array_unshift($a,$this->conn); return call_user_func_array($func,$a); }else{ // replace with your own error handler. die("$func is not a valid FTP function"); } } } // Example $ftp = new ftp('ftp.myserver.com'); $ftp->ftp_login('username','password'); var_dump($ftp->ftp_nlist()); ?> ---- Server IP: 208.69.120.55 Probable Submitter: 98.250.72.25 ---- Manual Page -- http://www.php.net/manual/en/book.ftp.php Edit -- https://master.php.net/note/edit/105868 Del: integrated -- https://master.php.net/note/delete/105868/integrated Del: useless -- https://master.php.net/note/delete/105868/useless Del: bad code -- https://master.php.net/note/delete/105868/bad+code Del: spam -- https://master.php.net/note/delete/105868/spam Del: non-english -- https://master.php.net/note/delete/105868/non-english Del: in docs -- https://master.php.net/note/delete/105868/in+docs Del: other reasons-- https://master.php.net/note/delete/105868 Reject -- https://master.php.net/note/reject/105868 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183327) next »