中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

PHP的FTP操作類( 拷貝、移動(dòng)、刪除文件 創(chuàng)建目錄 )

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
FTP操作類( 拷貝、移動(dòng)、刪除文件 創(chuàng)建目錄 ) class class_ftp{ public $off; 返回操作狀態(tài)(成功 失敗) public $conn
    <?php  
    /** 
    * 作用:FTP操作類( 拷貝、移動(dòng)、刪除文件/創(chuàng)建目錄 ) 
    * QQ交流群:136112330 
    */  
    class class_ftp  
    {  
        public $off; // 返回操作狀態(tài)(成功/失敗)  
        public $conn_id; // FTP連接  
        /** 
         * 方法:FTP連接 
         * @FTP_HOST -- FTP主機(jī) 
         * @FTP_PORT -- 端口 
         * @FTP_USER -- 用戶名 
         * @FTP_PASS -- 密碼 
         */  
        function __construct($FTP_HOST,$FTP_PORT,$FTP_USER,$FTP_PASS)  
        {  
            $this->conn_id = @ftp_connect($FTP_HOST,$FTP_PORT) or die("FTP服務(wù)器連接失敗");  
            @ftp_login($this->conn_id,$FTP_USER,$FTP_PASS) or die("FTP服務(wù)器登陸失敗");  
            @ftp_pasv($this->conn_id,1); // 打開被動(dòng)模擬  
        }  
        /** 
         * 方法:上傳文件 
         * @path -- 本地路徑 
         * @newpath -- 上傳路徑 
         * @type -- 若目標(biāo)目錄不存在則新建 
         */  
        function up_file($path,$newpath,$type=true)  
        {  
            if($type) $this->dir_mkdirs($newpath);  
            $this->off = @ftp_put($this->conn_id,$newpath,$path,FTP_BINARY);  
            if(!$this->off) echo "文件上傳失敗,請(qǐng)檢查權(quán)限及路徑是否正確!";  
        }  
        /** 
         * 方法:移動(dòng)文件 
         * @path -- 原路徑 
         * @newpath -- 新路徑 
         * @type -- 若目標(biāo)目錄不存在則新建 
         */  
        function move_file($path,$newpath,$type=true)  
        {  
            if($type) $this->dir_mkdirs($newpath);  
            $this->off = @ftp_rename($this->conn_id,$path,$newpath);  
            if(!$this->off) echo "文件移動(dòng)失敗,請(qǐng)檢查權(quán)限及原路徑是否正確!";  
        }  
        /** 
         * 方法:復(fù)制文件 
         * 說(shuō)明:由于FTP無(wú)復(fù)制命令,本方法變通操作為:下載后再上傳到新的路徑 
         * @path -- 原路徑 
         * @newpath -- 新路徑 
         * @type -- 若目標(biāo)目錄不存在則新建 
         */  
        function copy_file($path,$newpath,$type=true)  
        {  
            $downpath = "c:/tmp.dat";  
            $this->off = @ftp_get($this->conn_id,$downpath,$path,FTP_BINARY);// 下載  
            if(!$this->off) echo "文件復(fù)制失敗,請(qǐng)檢查權(quán)限及原路徑是否正確!";  
            $this->up_file($downpath,$newpath,$type);  
        }  
        /** 
         * 方法:刪除文件 
         * @path -- 路徑 
         */  
        function del_file($path)  
        {  
            $this->off = @ftp_delete($this->conn_id,$path);  
            if(!$this->off) echo "文件刪除失敗,請(qǐng)檢查權(quán)限及路徑是否正確!";  
        }  
        /** 
         * 方法:生成目錄 
         * @path -- 路徑 
         */  
        function dir_mkdirs($path)  
        {  
            $path_arr = explode('/',$path); // 取目錄數(shù)組  
            $file_name = array_pop($path_arr); // 彈出文件名  
            $path_div = count($path_arr); // 取層數(shù)  
            foreach($path_arr as $val) // 創(chuàng)建目錄  
            {  
                if(@ftp_chdir($this->conn_id,$val) == FALSE)  
                {  
                    $tmp = @ftp_mkdir($this->conn_id,$val);  
                    if($tmp == FALSE)  
                    {  
                        echo "目錄創(chuàng)建失敗,請(qǐng)檢查權(quán)限及路徑是否正確!";  
                        exit;  
                    }  
                    @ftp_chdir($this->conn_id,$val);  
                }  
            }  
            for($i=1;$i=$path_div;$i++) // 回退到根  
            {  
                @ftp_cdup($this->conn_id);  
            }  
        }  
        /** 
         * 方法:關(guān)閉FTP連接 
         */  
        function close()  
        {  
            @ftp_close($this->conn_id);  
        }  
    }// class class_ftp end  
    /************************************** 測(cè)試 *********************************** 
    $ftp = new class_ftp('192.168.100.143',21,'user','pwd'); // 打開FTP連接 
    //$ftp->up_file('aa.txt','a/b/c/cc.txt'); // 上傳文件 
    //$ftp->move_file('a/b/c/cc.txt','a/cc.txt'); // 移動(dòng)文件 
    //$ftp->copy_file('a/cc.txt','a/b/dd.txt'); // 復(fù)制文件 
    //$ftp->del_file('a/b/dd.txt'); // 刪除文件 
    $ftp->close(); // 關(guān)閉FTP連接 
    ******************************************************************************/  
    ?>   

CURL詳解
curl_close — 關(guān)閉一個(gè)curl會(huì)話
curl_copy_handle — 拷貝一個(gè)curl連接資源的所有內(nèi)容和參數(shù)
curl_errno — 返回一個(gè)包含當(dāng)前會(huì)話錯(cuò)誤信息的數(shù)字編號(hào)
curl_error — 返回一個(gè)包含當(dāng)前會(huì)話錯(cuò)誤信息的字符串
curl_exec — 執(zhí)行一個(gè)curl會(huì)話
curl_getinfo — 獲取一個(gè)curl連接資源句柄的信息
curl_init — 初始化一個(gè)curl會(huì)話

curl_multi_add_handle — 向curl批處理會(huì)話中添加單獨(dú)的curl句柄資源
curl_multi_close — 關(guān)閉一個(gè)批處理句柄資源
curl_multi_exec — 解析一個(gè)curl批處理句柄
curl_multi_getcontent — 返回獲取的輸出的文本流
curl_multi_info_read — 獲取當(dāng)前解析的curl的相關(guān)傳輸信息
curl_multi_init — 初始化一個(gè)curl批處理句柄資源
curl_multi_remove_handle — 移除curl批處理句柄資源中的某個(gè)句柄資源
curl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected"
curl_setopt_array — 以數(shù)組的形式為一個(gè)curl設(shè)置會(huì)話參數(shù)
curl_setopt — 為一個(gè)curl設(shè)置會(huì)話參數(shù)
curl_version — 獲取curl相關(guān)的版本信息
curl_init()函數(shù)的作用初始化一個(gè)curl會(huì)話,curl_init()函數(shù)唯一的一個(gè)參數(shù)是可選的,表示一個(gè)url地址。
curl_exec()函數(shù)的作用是執(zhí)行一個(gè)curl會(huì)話,唯一的參數(shù)是curl_init()函數(shù)返回的句柄。
curl_close()函數(shù)的作用是關(guān)閉一個(gè)curl會(huì)話,唯一的參數(shù)是curl_init()函數(shù)返回的句柄。

    <?php  
    $url = 'http://www.@@@@@@.com/';  
       //初始化curl  
    $curl = curl_init($url);  
    //curl超時(shí) 30s  
    curl_setopt($curl, CURLOPT_TIMEOUT, '30');  
    //user-agent頭  
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120722 Firefox/14.0.1");  
    //返回文件流  
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);  
    //打開頭文件數(shù)據(jù)流輸出  
    curl_setopt($curl, CURLOPT_HEADER, 1);  
    $string = curl_exec($curl);  
    var_dump($string);  
    preg_match_all('/Set-Cookie:\stest=(.*)/i', $string, $results);  
    var_dump($results);  
    ?>  

標(biāo)簽: ftp服務(wù)器 服務(wù)器 服務(wù)器登陸 權(quán)限

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:C#判斷網(wǎng)卡是否可用

下一篇: php利用GD庫(kù)生成縮略圖