글
디렉토리에서 파일 목록 추출해서 돌리고 삭제하기
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
</head>
<body>
<?
require_once "/data/common/common.inc.php";
unset($data);
unset($stack);
$stack = array();
function startTag($parser, $name, $attrs)
{
global $stack;
$tag=array("name"=>$name,"attrs"=>$attrs);
array_push($stack,$tag);
}
function cdata($parser, $cdata)
{
global $data_xml,$stack,$top,$s_result,$data,$file;
if(trim($cdata))
{
$stack[count($stack)-1]['cdata']=$cdata;
}
}
function endTag($parser, $name)
{
global $data_xml,$stack,$top,$s_result,$data,$file;
$stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
array_pop($stack);
}
function search_go($xml_name)
{
global $data_xml,$stack,$top,$s_result,$data,$file;
$sp[host]="news.sunzio.com"; //domain or ip
$port=80;
$sp[path] = "/cron/aving/".$xml_name.'.xml'; //디렉토리 경로.
//echo "$sp[host]$sp[path]<br>";
$fsp = fsockopen ("$sp[host]", $port, $errno, $errstr, 30);
if (!$fsp)
{
echo "$errstr ($errno)<br>\n";
}
else
{
$refer = "Referer: $referer\r\n";
$request.="GET ".$sp[path]." HTTP/1.0\r\n";
$request.="Accept: */*\r\n";
$request.="Accept: ko\r\n";
$request.="Accept-Encoding: gzip, deflate\r\n";
$request.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 1.1.4322)\r\n";
$request.="Host: ".$sp["host"]."\r\n";
$request.=$refer;
$request.="Content-type: application/x-www-form-urlencoded\r\n";
$request.="Connection: close\r\n";
$request.="\r\n";
fputs($fsp , $request);
while(! feof ($fsp))
{ // 데이터 저장
$file .= fgets ($fsp, 1024);
}
//$file = 'simple.xml';
$tmp = explode('<?xml version="1.0" encoding="euc-kr"?>',$file);
$file = '<?xml version="1.0" encoding="euc-kr"?>' . $tmp[1];
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");
//$data = xml_parse($xml_parser,file_get_contents($file));
$data = xml_parse($xml_parser,$file);
if(!$data) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
}
fclose ($fsp);
$top =$stack[0][children];
return $top;
}
$dir ="/data/news/cron/aving"; //절대경로
$files = scandir($dir);//$files-배열형태로파일명을 가지고 있음
for($i=2;$i<sizeof($files);$i++)
{
$x_n=$files[$i];
$x_ne=explode('.',$x_n);
$xml_name=$x_ne[0];
//echo"$xml_name ----<br>";
$re=search_go($xml_name);
$k=sizeof($top)-1;
$seq='aivng'.$top[1][cdata]; //뉴스넘버 seq
$sub=addslashes(trim(iconv("UTF-8", "EUC-KR ",substr($top[7][cdata],0,200)))); //서브타이틀
$nd=$top[4][cdata]; //날짜년월일까지만
$tp=$top[8][attrs][CODE]; //카테고리 코드
$cate=trim(iconv("UTF-8", "EUC-KR ",$top[8][attrs][NAME])); // 카테고리 네임
$title=addslashes(trim(iconv("UTF-8", "EUC-KR ",$top[3][cdata])));//제목
$imageurl=$top[9][attrs][HREF]; //이미지1
$imageurl2=$top[10][attrs][HREF]; //이미지1
$imageurl3=$top[11][attrs][HREF]; //이미지1
$imageurl4=$top[12][attrs][HREF]; //이미지1
$url=$top[$k][attrs][HREF];//url
$reg_dt=$top[4][cdata].' '.$top[5][cdata];//기사일자 년월일시분초
$content=addslashes(trim(trim(iconv("UTF-8", "EUC-KR ",$top[7][cdata]))));//내용
echo "<br>=====================================<br>
$k<br>
$x_n <br>
seq ==> $seq<br>
nd ==> $nd<br>
tp ==> $tp<br>
cate ==> $cate <br>
title ==> $title<br>
imageurl ==> $imageurl<br>
imageurl2 ==> $imageurl2<br>
imageurl3 ==> $imageurl3<br>
imageurl4 ==> $imageurl4<br>
url ==> $url<br>
reg_dt ==> $reg_dt <br>
";
$cq="select cate_code2,cate_name from news.category where cate_code='$tp'";
$c_c=MW_FETCH_ONE($cq,$CONN[news]);
$qc="select seq from news.NEWS where seq='$seq' and tp='$c_c[cate_code2]'";///////////이미들어가있는기사인지체크
//echo "$qc <br>";
$b_z=MW_RESULT_ONE($qc,$CONN[news]);
if(empty($b_z))
{
$q="insert into news.NEWS (tp,seq,cate,title,subtitle,ndate,imageurl,imageurl2,imageurl3,imageurl4,url,reg_dt,content)
values ('$c_c[cate_code2]','$seq','$c_c[cate_name]','$title','$sub','$nd','$imageurl','$imageurl2','$imageurl3','$imageurl4','$url','$reg_dt','$content')";
MW_QUERY($q,$CONN[news]);
}
$filen=$dir.'/'.$x_n;
ftp_del($filen);
unset($data);
unset($stack);
$stack = array();
unset($data_xml);
unset($top);
unset($s_result);
unset($data);
unset($file);
}
//이미지 서버 엡튀피 연결
function ftp_con()
{
global $_SET;
$ftp_server = "";
$ftp_user = "";
$ftp_pass = "";
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
return $conn_id;
}
//ftp 파일 삭제
function ftp_del($del_file)
{
if ($del_file != "")
{
$conn_id = ftp_con();
@ftp_delete($conn_id, $del_file);
ftp_close($conn_id);
}
}
?>
</body>
</html>
'렛츠웹 + 게임 > My Tip' 카테고리의 다른 글
이미지플로팅 핫베스트등 (0) | 2009.01.05 |
---|---|
트리메뉴 (0) | 2009.01.05 |
ftp 접속하고 목록 뽑아서 파일 복사해오기 (0) | 2009.01.05 |
계급아이콘,아바타 (0) | 2009.01.05 |
보드생성 관리 소스 (0) | 2009.01.05 |