Contents

조회 수 16354 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
<사용방법> 
1. php가 지원되는 계정에 본 파일을 업로드한다. (예:http://slrclub.com/cyworld.php) 
2. 싸이월드에 올려둔 사진의 url을 확인한다. url에서 서버위치와 파일 이름(redirect뒷 부분)을 복사한다. 
(예:http://cyimg.cyworld.nate.com/common/file_down.asp?redirect=%2Fd11003%2F2004%2F12%2F14%2F8%2FIMG%5F2904%2Ejpg) 
위의 예에서 host는 cyimg입니다. 예전 홈피의 경우 img일겁니다. 
3. 원하는 곳에 가서 img태그로 다음과 같이 연결한다. 
<img src="http://slrclub.com/cyworld.php?host=cyimg&redirect=%2Fd11003%2F2004%2F12%2F14%2F8%2FIMG%5F2904%2Ejpg" /> 
만약 host가 cyimg인 경우에는 host=cyimg&를 생략해도 됩니다. 

사용예: 싸이월드에 올려진 파일을 외부링크 걸고 싶을때 cyworld.php 라는 파일을 php가 지원되는 계정에 업로드 한 다음에 이 파일을 이용해서 불러들이면 됩니다. 

-- 소스 -- 
<? 
    if( !$redirect ) exit(); 
    if( !$host ) $host = "cyimg"; 
    
    $url = "http://".$host.".cyworld.nate.com/common/file_down.asp"; 
    
    $http = new Http; 
    $http->is_bin = 1; 
    $http->is_bin_len = 1024000; 
    $http->setURL( $url ); 
    $http->setParam("redirect", urldecode($redirect)); 
    $http->setCookie("ETC", "Referer=True"); // 쿠키 세팅 
    $result = $http->send("GET"); 
    echo( $result ); 
?> 
<? 
    /** 
    * HTTP 소켓 클래스 
    * 
    * @author 희망주기 (hopegiver@korea.com) 
    * @date 2002-09-06 
    * @access public 
    */ 
    class Http { 
        
        var $host; 
        var $port; 
        var $path; 
        var $cookie; 
        var $variable; 
        var $referer; 
        var $_header; 
        var $auth; 
        var $debug; 
        var $query; 
        var $is_bin; 
        var $is_bin_len; 
        
        # constructor 
        function Http($url="") { 
            $this->port = 80; 
            $this->is_bin = 0; 
            $this->is_bin_len = 102400; 
            if($url) $this->setURL($url); 
        } 
    
        /** 
        * URL 지정함수 
        * 
        * @param string $url : URL 
        * @return boolean 
        */ 
        function setURL($url) { 
            // if(!$m = parse_url($url)) return $this->setError("파싱이 불가능한 URL입니다."); 
            if(!$m = parse_url($url)) return 0; 
            // if($m['scheme'] != "http") return $this->setError("HTTP URL이 아닙니다."); 
            if($m['scheme'] != "http") return 0; 
            
            $this->host = $m['host']; 
            $this->port = ($m['port']) ? $m['port'] : 80; 
            $this->path = ($m['path']) ? $m['path'] : "/"; 
            if($m['query']) { 
                $arr1 = explode("&", $m['query']); 
                foreach($arr1 as $value) { 
                    $arr2 = explode("=", $value); 
                    $this->setParam($arr2[0], $arr2[1]); 
                } 
            } 
            if($m['user'] && $m['pass']) $this->setAuth($m['user'], $m['pass']); 
            
            return true; 
        } 
    
        /** 
        * 변수값을 지정한다. 
        * 
        * @param string $key : 변수명, 배열로도 넣을수 있다. 
        * @param string $value : 변수값 
        */ 
        function setParam($key, $value="") { 
            if(is_array($key)) foreach($key as $k => $v) $this->variable[$k] = $v; 
            else $this->variable[$key] = $value; 
        } 
        
        /** 
        * Referer를 지정한다. 
        * 
        * @param string $referer : Referer 
        */ 
        function setReferer($referer) { 
            $this->referer = $referer; 
        } 
    
        /** 
        * 쿠키를 지정한다. 
        * 
        * @param string $key : 쿠키변수명, 배열로도 넣을수 있다. 
        * @param string $value : 쿠키변수값 
        */ 
        function setCookie($key, $value="") { 
            if(is_array($key)) foreach($key as $k => $v) $this->cookie .= "; $k=$v"; 
            else $this->cookie .= "; $key=$value"; 
            if(substr($this->cookie, 0, 1) == ";") $this->cookie = substr($this->cookie, 2); 
        } 
        
        /** 
        * 인증설정함수 
        * 
        * @param string $id : 아이디 
        * @param string $pass : 패스워드 
        */ 
        function setAuth($id, $pass) { 
        $    this->auth = base64_encode($id.":".$pass); 
        } 
        
        /** 
        * POST 방식의 헤더구성함수 
        * 
        * @return string 
        */ 
        function postMethod() { 
            if(is_array($this->variable)) { 
                $parameter = "\r\n"; 
                foreach($this->variable as $key => $val) { 
                    $parameter .= trim($key)."=".urlencode(trim($val))."&"; 
                } 
                $parameter .= "\r\n"; 
            } 
            $query .= "POST ".$this->path." HTTP/1.0\r\n"; 
            $query .= "Host: ".$this->host."\r\n"; 
            if($this->auth) $query .= "Authorization: Basic ".$this->auth."\r\n"; 
            if($this->referer) $query .= "Referer: ".$this->referer."\r\n"; 
            if($this->cookie) $query .= "Cookie: ".$this->cookie."\r\n"; 
            $query .= "User-agent: PHP/HTTP_CLASS\r\n"; 
            $query .= "Content-type: application/x-www-form-urlencoded\r\n"; 
            $query .= "Content-length: ".strlen($parameter)."\r\n"; 
            if($parameter) $query .= $parameter; 
            $query .= "\r\n"; 
            return $query; 
        } 
        
        /** 
        * GET 방식의 헤더구성함수 
        * 
        * @return string 
        */ 
        function getMethod() { 
            if(is_array($this->variable)) { 
                $parameter = "?"; 
                foreach($this->variable as $key => $val) { 
                    $parameter .= trim($key)."=".urlencode(trim($val))."&"; 
                } 
                //$parameter = substr($parameter, 0, -1); 
            } 
            
            $query = "GET ".$this->path.$parameter." HTTP/1.0\r\n"; 
            $query .= "Host: ".$this->host."\r\n"; 
            if($this->auth) $query .= "Authorization: Basic ".$this->auth."\r\n"; 
            if($this->referer) $query .= "Referer: ".$this->referer."\r\n"; 
            if($this->cookie) $query .= "Cookie: ".$this->cookie."\r\n"; 
            $query .= "User-agent: PHP/HTTP_CLASS\r\n"; 
            $query .= "\r\n"; 
            return $query; 
        } 
        
        /** 
        * 데이타 전송함수 
        * 
        * @param string $mode : POST, GET 중 하나를 입력한다. 
        * @return string 
        */ 
        function send($mode="GET") { 
        
            // 웹서버에 접속한다. 
            $fp = fsockopen($this->host, $this->port, $errno, $errstr, 10); 
            // if(!$fp) return $this->setError($this->host."로의 접속에 실패했습니다."); 
            if(!$fp) return 0; 
            
            // GET, POST 방식에 따라 헤더를 다르게 구성한다. 
            if(strtoupper($mode) == "POST") $this->query = $this->postMethod(); 
            else $this->query = $this->getMethod(); 
            
            fputs($fp,$this->query); 
            
            // 헤더 부분을 구한다. 
            $this->_header = ""; // 헤더의 내용을 초기화 한다. 
            while(trim($buffer = fgets($fp,1024)) != "") { 
                $this->_header .= $buffer; 
            } 
            
            // 바디 부분을 구한다. 
            if( $this->is_bin ) { 
                $body = fread($fp, $this->is_bin_len); 
            } else { 
                while(!feof($fp)) { 
                $body .= fgets($fp,1024); 
                } 
            } 
        
            // 접속을 해제한다. 
            fclose($fp); 
        
            return $body; 
        } 
        
        /** 
        * 헤더를 구하는 함수 
        * 
        * @return string 
        */ 
        function getHeader() { 
            return $this->_header; 
        } 
        
        /** 
        * 쿠키값을 구하는 함수 
        * 
        * @param string $key : 쿠키변수 
        * @return string or array 
        */ 
        function getCookie($key="") { 
            if($key) { 
                $pattern = "/".$key."=([^;]+)/"; 
                if(preg_match($pattern, $this->_header, $ret)) return $ret[1]; 
            } else { 
                preg_match_all("/Set-Cookie: [^\n]+/", $this->_header, $ret); 
                return $ret[0]; 
            } 
        } 
    
    } 
?> 
-- / 소스 -- 
    
출처 : http://www.slrclub.com/


?

  1. 영어. 불규칙 동사 정리

    Date2017.10.04 CategoryEtc Byhooni Views3526
    Read More
  2. 영어. 반드시 외워야 할 영어 숙어

    Date2016.07.07 CategoryEtc Byhooni Views6346
    Read More
  3. [english] 영어공부 혼자 하기, 인터넷으로 영어공부하기 추천사이트 20선

    Date2013.11.25 CategoryEtc Byhooni Views9411
    Read More
  4. 논문(BHO)에 들어갈 내용 집에가서 테스트 해볼 것..

    Date2013.05.28 CategoryEtc Byhooni Views10230
    Read More
  5. [NFC] 단말기와 서버 통신 내용

    Date2013.11.12 CategoryEtc Byhooni Views11197
    Read More
  6. [flash] 맘에 드는 파이차트

    Date2013.04.23 CategoryEtc Byhooni Views12591
    Read More
  7. 선과 악에 대한 영어논술문항(지킬앤하이드 독서 후 이어지는 심화 수행평가)

    Date2013.12.04 CategoryEtc Byhooni Views12750
    Read More
  8. [htm] DOM에 대해 ㅎㅎ

    Date2003.04.23 CategoryEtc Byhooni Views14718
    Read More
  9. 여러 대학 및 권위있는 기관 강좌 모음 ㅋㅋ

    Date2013.06.17 CategoryEtc Byhooni Views15124
    Read More
  10. 영어의 12 시제 (The twelve tenses of English)

    Date2013.07.12 CategoryEtc Byhooni Views15703
    Read More
  11. 티스토리 테이블 html,css 구문

    Date2013.11.03 CategoryEtc Byhooni Views15966
    Read More
  12. 여기저기서 모은 VoIP(인터넷전화) 자료들~

    Date2013.04.23 CategoryEtc Byhooni Views15967
    Read More
Board Pagination Prev 1 2 3 4 5 6 Next
/ 6