class Curl_Ftp
{
private $ftp_user;            //FTP用户名
private $ftp_pass;            //FTP密码
private $ftp_add;             //FTP地址

private $ftp_file;            //上传文件
private $ftp_dir;             //上传目录

public function __construct($ftpuser, $ftppass, $ftpadd)
{
$this->ftp_user = $ftpuser;
$this->ftp_pass = $ftppass;
$this->ftp_add  = $ftpadd;
}





public function FTP($file,)
{
$ch = curl_init();
$fp = fopen($file,'r');
//curl_setopt($ch, CURLOPT_URL, $ftpuser.$filename); 

curl_setopt($ch, CURLOPT_URL, $ftpadd.$file);
curl_setopt($ch, CURLOPT_USERPWD,"$ftpuser:$ftppass");

  curl_setopt($ch, CURLOPT_UPLOAD, 1);  
    curl_setopt($ch, CURLOPT_INFILE, $fp);  
    curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));  
    curl_exec ($ch);  
     
    $error_no = curl_errno($ch);
      curl_close ($ch);
}


}
我的这个FTP方法,要怎么写啊? 传参

解决方案 »

  1.   

    $ftpses = new Curl_Ftp($username, $pwd, $address);
    $ftpses->FTP($file);
      

  2.   

    public function FTP($file)
                {
                    $ch = curl_init();
                    $fp = fopen($file,'r');
                    //curl_setopt($ch, CURLOPT_URL, $ftpuser.$filename); 
                    
                    curl_setopt($ch, CURLOPT_URL, $ftpadd.$file);
                    curl_setopt($ch, CURLOPT_USERPWD,"$ftpuser:$ftppass");
                    
                         curl_setopt($ch, CURLOPT_UPLOAD, 1);  
                           curl_setopt($ch, CURLOPT_INFILE, $fp);  
                           curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));  
                           curl_exec ($ch);  
                    
                    $error_no = curl_errno($ch);
                     curl_close ($ch);
                }我是说这一段里面,在构造函数后,与构造函数相同的参数值就可以这样直接使用了是吗?
      

  3.   

    public function FTP($file)
                {
                    $ch = curl_init();
                    $fp = fopen($file,'r');
                    //curl_setopt($ch, CURLOPT_URL, $this->$ftpuser.$filename); 
                    
                    curl_setopt($ch, CURLOPT_URL, $this->$ftpadd.$file);
                    curl_setopt($ch, CURLOPT_USERPWD,"$this->$ftpuser:$this->$ftppass");
                    
                         curl_setopt($ch, CURLOPT_UPLOAD, 1);  
                           curl_setopt($ch, CURLOPT_INFILE, $fp);  
                           curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));  
                           curl_exec ($ch);  
                    
                    $error_no = curl_errno($ch);
                     curl_close ($ch);
                }
      

  4.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <?php
    include("Class_Curl_Ftp.php");$ftp_user = '123456';            
    $ftp_pass ='123456';            //FTP密码
    $ftp_add ='ftp://192.168.1.2/';   
    $up = new Curl_Ftp($ftp_user, $ftp_pass, $ftp_add);
    //print_r($up);
    //exit;
    if(isset($_POST['submit'])) {  
       if (!empty($_FILES['file']['name'])) {  

    $file = $_FILES['file']['name'];
    print_r($file);
    exit;
    $up->FTP($file);
    }
    }
    ?>
    <body>
    <form action="" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" name="submit" value="上传">
    </form>
    </body>
    </html>这是哪里错了呢?
      

  5.   

    你print之后,都exit了,还执行啥?