CURL FTP 上传文件

技术文档 - PHP文档 作者: xcheng1986 发布于:2014-05-27 阅读(985) (暂无评论)  

    /**
     * FTP上传文件
     * @param String $src 文件的相对路径
     * @return boolean
     */
    public function upFile() {
        $ch = curl_init();
        if ($fp = fopen($src, 'r')) {
            $file_name = basename($src);
            curl_setopt($ch, CURLOPT_URL, 'ftp://' . FTP_USER . ':' . FTP_PASS . '@' . FTP_SERVER . '/tmp/' . $file_name);
            curl_setopt($ch, CURLOPT_UPLOAD, 1);
            curl_setopt($ch, CURLOPT_INFILE, $fp);
            curl_setopt($ch, CURLOPT_INFILESIZE, filesize($src));
            curl_exec($ch);
            $error_no = curl_errno($ch);
            curl_close($ch);
            if ($error_no != 0)
                return false;
            return true;
        }else {
            return false;
        }
    }