html - Uploading mp3 file to FTP using PHP -
i'm new - i'm trying upload file ftp using following 2 classes, keeps failing upload
//class.ftp.php class constructor input: 1. server name 2. user name 3. user password 4. destination directory */ class ftp { var $ftp_server; var $ftp_user_name; var $ftp_user_pass; var $dst_dir; var $conn_id; var $login_result; function ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir) { if ($ftp_server!="" && $ftp_user_name!="" && $ftp_user_pass!="" && $dst_dir!="") { $this->ftp_server = $ftp_server; $this->ftp_user_name = $ftp_user_name; $this->ftp_user_pass = $ftp_user_pass; $this->dst_dir = $dst_dir; } else return false; // bad parametrs if (!$this->connect() || !$this->setdir()) return false; // bad connect or no exist directory else return true; // ok } /* ftp connect */ function connect() { $this->conn_id = @ftp_connect($this->ftp_server); $this->login_result = @ftp_login($this->conn_id, $this->ftp_user_name, $this->ftp_user_pass); if ((!$this->conn_id) || (!$this->login_result)) return false; else return true; } /* set directory */ function setdir() { if (!@ftp_chdir($this->conn_id, $this->dst_dir)) return false; else return true; } /*send file */ input: $remote_file -> file send $file -> read file $mode -> "ftp_binary","ftp_ascii",... */ function sendfile($remote_file, $file, $mode="ftp_binary") { if (@ftp_put($this->conn_id, $remote_file, $file, $mode)) return true; else return false; } } //end class //test class //$path = 1852 - future father-in-law on birthday.mp3 //$dst_dir = /htdocs/site2/telemessages/en/birthdays/child/ $send_file = $path; // file sending $remote_file = $path; // destination file $ftp_server = "213.171.193.5"; // server name $ftp_user_name = "************"; // user name $ftp_user_pass = "*************"; // password $dst_dir = "/htdocs/site2/telemessages/en/".$_session['dir']; // destination directory ( www/upload/ ) //include class include ('class.ftp.php'); //class constructor $ftp = new ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir); // sending file // ftp_ascii or ftp_binary $err = $ftp->sendfile($remote_file, $send_file, "ftp_binary"); echo "test"; if (!$err) echo "no transfer !"; else echo "transfer ok."; i keep getting message "no transfer !" , i'm not sure meant assigned $remote_file variable.
thanks in advance!
use 'error_reporting(e_all);' turn error reporting on. should give more detailed information causing transfer fail.
Comments
Post a Comment