2007. 9. 12. 10:15
웹파일(원격)을 로컬에 저장하는 함수
2007. 9. 12. 10:15 in 자작소스/PHP
<?php /** * 원격파일을 로컬에 저장 * * @param text $url * @param text $savefile */ function getRemoteFile($url,$savefile) { $dirname = dirname($savefile); $url_info = parse_url($url); if(!is_dir($dirname)) { mkdir($dirname,0777); } $fp = fsockopen($url_info['host'], 80); if(!$fp) { return FALSE; } $fp1 = fopen($savefile,'w+'); if(!$fp1) { return FALSE; } fputs($fp,"GET ".$url_info['path'].($url_info['query'] ? '?'.$url_info['query'] : '')." HTTP/1.0\r\n"); fputs($fp,"Host: ".$url_info['host']."\r\n"); fputs($fp,"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n"); fputs($fp,"Connection: close\r\n\r\n"); while(trim($buf = fgets($fp,1024))) {} //헤더부분 건너뜀 while(!feof($fp)) { fwrite($fp1,fgets($fp,1024)); } fclose($fp1); fclose($fp); return TRUE; } ?>