简体   繁体   中英

Uploading mp3 file to FTP using PHP

I'm very new to this - I'm trying to upload a file to an FTP using the following 2 classes, However it keeps failing to 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; // ALL 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 for 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 your birthday.mp3
//$dst_dir = /htdocs/site2/telemessages/en/birthdays/Child/

$send_file = $path;     // file for 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 any 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 the message "No transfer !" and I'm also not sure what is meant to be assigned to $remote_file variable.

Thanks in advance!

Use 'error_reporting(E_ALL);' to turn error reporting on. That should give you more detailed information about exactly what is causing the transfer to fail.

Error Reporting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM