使用PHP将mp3文件上传到FTP

时间:2013-07-18 15:14:48

标签: php html file-upload web ftp

我对此非常陌生 - 我正在尝试使用以下2个类将文件上传到FTP,但它仍无法上传

//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.";

我一直收到消息“没有转移!”而且我也不确定要分配给$ remote_file变量的是什么。

提前致谢!

1 个答案:

答案 0 :(得分:0)

使用'error_reporting(E_ALL);'打开错误报告。这应该会为您提供有关导致转移失败的确切原因的更详细信息。

Error Reporting