[PHP] curl을 이용한 이미지 다운로드

PHP
curl를 이용해서 웹 이미지 다운로드 이번에는 전체 소스가 없습니다.초기에 만들고 계속 수정에 수정을 거듭하다보니 저 혼자만 사용할 수 있는 조금 난해한 코드들이 넘쳐나게 되 간한히 함수랑 사용방법의 코드만 올려 놓습니다. public function getImage($url) { curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 인증서 체크같은데 true 시 안되는 경우가 많다. curl_setopt($ch, CURLOPT_POST, false); // Post Get 접속 여부 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_TIMEOUT, 60); // TimeOut 값 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //http 응답코드가 302일때 redirect_url 로 따라감 curl_setopt($ch, CURLOPT_MAXREDIRS, 5); //if http server gives redirection responce curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 결과값을 받을것인지 $data = curl_exec($this->ch); $return = base64_encode($data); return $return; } 위에 함수를 사용하면은 웹에서 이미지를 가져 올 수 있습니다.이미지의 접속가능한 URL이 있어야 접속이 됩니다. $curlDataImg = new curlData(); $returnImgBase64 = $curlDataImg->getImage($urlImg); $imageSource = base64_decode( $returnImgBase64 ); 위에 코드를 이용해서 이미지의 바이너리를 확인해…
Read More

[PHP] CURL 설정

PHP
NAME CURLOPT_SSLVERSION - set preferred TLS/SSL version SYNOPSIS #include <curl/curl.h> CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSLVERSION, long version); DESCRIPTION Pass a long as parameter to control which version of SSL/TLS to attempt to use. Use one of the available defines for this purpose. The available options are:   CURL_SSLVERSION_DEFAULT The default action. This will attempt to figure out the remote SSL protocol version. CURL_SSLVERSION_TLSv1 TLSv1.x CURL_SSLVERSION_SSLv2 SSLv2 CURL_SSLVERSION_SSLv3 SSLv3 CURL_SSLVERSION_TLSv1_0 TLSv1.0 (Added in 7.34.0) CURL_SSLVERSION_TLSv1_1 TLSv1.1 (Added in 7.34.0) CURL_SSLVERSION_TLSv1_2 TLSv1.2 (Added in 7.34.0) DEFAULT CURL_SSLVERSION_DEFAULT PROTOCOLS All TLS based protocols: HTTPS, FTPS, IMAPS, POP3, SMTPS etc. EXAMPLE   CURL *curl = curl_easy_init(); if(curl) {   curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");   /* ask libcurl to use TLS version 1.0 or later */   curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);   /* Perform the request */  …
Read More

[PHP] CURL을 이용한 RSS 파서

프로그램
RSS 2.0, RSS 1.0, ATOM 을 대용하기 위해서 한개의 파일로 만들려고 노력을 하였지만 잘 되지 않았습니다. <?php class RssParser { var $Agent = "MyAgent"; var $CookieNM = "./cookie.txt"; var $debug = false; function RssParser() { } function RssGet ($RssURL, $RssParam='') { $this->URL = $RssURL; $this->Param = $RssParam; $this->GetHeader(); $this->RssGetAccess(); $this->RssXMLLoad(); // xml 중 테이터가 있을 경우에만 결과값을 돌려줌 if(empty($this->xml->channel->title) == false) { return $this->MyParser(); } } function RssPost ($RssURL, $RssData) { $this->URL = $RssURL; $this->Data = $RssData; $this->ContentLength = strlen($this->Data); } function GetHeader() { //"GET ".$this->Param." HTTP/1.1", $this->Headers = array( "Content-type: application/xml;charset=\"utf-8\"", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: ko-kr,ko;q=0.8,en-us;q=0.5,en;q=0.3", "Accept-Encoding: ", "Accept-Charset: EUC-KR,utf-8;q=0.7,*;q=0.7", "Keep-Alive: 300", "Connection: keep-alive", "" ); } /** * 실제 데이터 얻어 오는 부분 **/ function RssGetAccess() { $ch = curl_init(); curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false); curl_setopt($ch, CURLOPT_URL, $this->URL); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->Headers);…
Read More