[英]Uploading mp3 file to FTP using PHP
我对此很陌生-我正在尝试使用以下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变量什么意思。
提前致谢!
使用'error_reporting(E_ALL);' 打开错误报告。 这应该为您提供有关导致传输失败的确切原因的更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.