php - 소켓으로 이미지파일을 로컬에 저장하기
마스터욱
0
30
0
0
2017-02-26 02:11:24
1 2 3 4 5 6 7 8 9 10 11 12 | $fp = fsockopen('phpschool.com',80,$errno,$errstr,10); if ( $fp ) { $send = 'GET /images/common/top/phpschool_top_logo.png HTTP/1.0'."\r\n"; $send.= 'Host: phpschool.com'."\r\n"; $send.= 'Connection: Close'."\r\n\r\n"; fwrite($fp,$send); $content = ''; while ( !feof($fp) ) $content.= fread($fp,1024); $content = substr($content,strpos($content,"\r\n\r\n")+4); fclose($fp); file_put_contents('./phpschool_top_logo.png',$content); } | cs |
뭐 간단하게 phpschool.com 의 로고를 로컬에 저장하는 소스이다.
스누피(snoopy) 라이브러리를 사용하면 더 간결하게 만들수도 있다.