글
타서버 특정 폴더에 있는 다수의 파일들을 우리서버에 저장하고 해당 파일들을 읽어서 정보를 처리한다
렛츠웹 + 게임/My Tip
2009. 1. 5. 17:25
1) 접속하여 해당 폴더에 파일들을 읽고 가져와서 우리쪽에 저장한다
<?
include("/data/common/mw.func.inc.php");
$ftp_server = "";
$ftp_user = "";
$ftp_pass = "";
$ftproot ="/www/idconv/MOVIE";
// 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";
}
// turn passive mode on
ftp_pasv($conn_id, true);
$files = ftp_nlist($conn_id, ".");
echo "<pre>";
print_r($files);
for($i=0;$i<sizeof($files);$i++)
{
$x_n=$files[$i];
echO "$x_n <br>";
$local_file='/data/product/'.$x_n;
$server_file=$x_n;
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file<br>";
} else {
echo "There was a problem $local_file <br>";
}
/*
if (ftp_delete($conn_id, $x_n)) {
echo "$file deleted successful $x_n<br><br>";
} else {
echo "could not delete $x_n<br><br>";
}
*/
}
?>
2) 해당 폴더에 파일들을 읽어서 처리 한다
<?
include("/data/common/mw.func.inc.php");
$dir ="/data/product"; //절대경로
$files = scandir($dir);//$files-배열형태로파일명을 가지고 있음
for($i=2;$i<sizeof($files);$i++)
{
$x_n=$files[$i];
$fn=$dir.'/'.$x_n;
echo "$i $fn------------------------------------------------------------------<br>";
$f_p=fopen($fn,'r');
unset($str);
unset($arr);
while(!feof($f_p))
{
$str = fgets($f_p,10000);
$arr[]=chop($str);
}
for($k=0;$k<sizeof($arr);$k++)
{
//$arrr[$i][$k][1]=='SUCC';
if($arr[$k]!='')
{
$arrr[$i][$k]=explode('|',$arr[$k]);
/* */
$q="select * from copyright_contentid where ContentID='".$arrr[$i][$k][1]."'";
echo "$q<br>";
$row=MW_FETCH_ONE($q,$CONN[master]);
if($row[ContentID]!='')
{
$N_price=$arrr[$i][$k][3];
if($row[Price]!=$N_price)
{
$qq="update oncx_copyright_contentid set Price=$arrr[$i][$k][3] where ContentID='$arrr[$i][$k][1]'";
echo "$qq<br>";
}else{
echo"$row[Price] != $N_price <br>";
}
}else{
$qqq="insert into oncx_copyright_contentid (ContentID,Title,Price,Author,Writer) values
('".$arrr[$i][$k][1]."','".$arrr[$i][$k][7]."','".$arrr[$i][$k][3]."','kth','kth')";
echo "$qqq<br>";
}
/* */
}
}
fclose($f_p);
if(!@unlink($fn))
{
dile('오류:파일삭제실패');
}else{
echo" <br> 삭제성공 $fn <br>";
}
}
?>
<?
include("/data/common/mw.func.inc.php");
$ftp_server = "";
$ftp_user = "";
$ftp_pass = "";
$ftproot ="/www/idconv/MOVIE";
// 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";
}
// turn passive mode on
ftp_pasv($conn_id, true);
$files = ftp_nlist($conn_id, ".");
echo "<pre>";
print_r($files);
for($i=0;$i<sizeof($files);$i++)
{
$x_n=$files[$i];
echO "$x_n <br>";
$local_file='/data/product/'.$x_n;
$server_file=$x_n;
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file<br>";
} else {
echo "There was a problem $local_file <br>";
}
/*
if (ftp_delete($conn_id, $x_n)) {
echo "$file deleted successful $x_n<br><br>";
} else {
echo "could not delete $x_n<br><br>";
}
*/
}
?>
2) 해당 폴더에 파일들을 읽어서 처리 한다
<?
include("/data/common/mw.func.inc.php");
$dir ="/data/product"; //절대경로
$files = scandir($dir);//$files-배열형태로파일명을 가지고 있음
for($i=2;$i<sizeof($files);$i++)
{
$x_n=$files[$i];
$fn=$dir.'/'.$x_n;
echo "$i $fn------------------------------------------------------------------<br>";
$f_p=fopen($fn,'r');
unset($str);
unset($arr);
while(!feof($f_p))
{
$str = fgets($f_p,10000);
$arr[]=chop($str);
}
for($k=0;$k<sizeof($arr);$k++)
{
//$arrr[$i][$k][1]=='SUCC';
if($arr[$k]!='')
{
$arrr[$i][$k]=explode('|',$arr[$k]);
/* */
$q="select * from copyright_contentid where ContentID='".$arrr[$i][$k][1]."'";
echo "$q<br>";
$row=MW_FETCH_ONE($q,$CONN[master]);
if($row[ContentID]!='')
{
$N_price=$arrr[$i][$k][3];
if($row[Price]!=$N_price)
{
$qq="update oncx_copyright_contentid set Price=$arrr[$i][$k][3] where ContentID='$arrr[$i][$k][1]'";
echo "$qq<br>";
}else{
echo"$row[Price] != $N_price <br>";
}
}else{
$qqq="insert into oncx_copyright_contentid (ContentID,Title,Price,Author,Writer) values
('".$arrr[$i][$k][1]."','".$arrr[$i][$k][7]."','".$arrr[$i][$k][3]."','kth','kth')";
echo "$qqq<br>";
}
/* */
}
}
fclose($f_p);
if(!@unlink($fn))
{
dile('오류:파일삭제실패');
}else{
echo" <br> 삭제성공 $fn <br>";
}
}
?>
'렛츠웹 + 게임 > My Tip' 카테고리의 다른 글
서브넷 (Subnet)과 서브넷 마스크 (mask) (0) | 2009.01.21 |
---|---|
인터넷의 기초 (0) | 2009.01.13 |
이미지플로팅 핫베스트등 (0) | 2009.01.05 |
트리메뉴 (0) | 2009.01.05 |
디렉토리에서 파일 목록 추출해서 돌리고 삭제하기 (0) | 2009.01.05 |