관리 메뉴

웹개발자의 기지개

[PHP] CSV 일괄 업로드 작업 본문

PHP

[PHP] CSV 일괄 업로드 작업

웹개발자 워니 2025. 6. 27. 04:46

CSV 일괄 업로드 파일 작업하기

 

[CSV 파일]

 

(주)테스트엘리베이터|가나다|전북|전라북도 완주군 삼례읍 1234|063-1111-2222|063-222-2222
테스트회사㈜|이순신|인천|인천광역시 부평구 경원대로 1234호|02-2222-3333|02-2222-3334
(주) 테스트나라|서테스트|경기|경기도 부천시 원미구 길주로 303호|032-333-4444|032-333-5555

 

 

[ csv_up.php ]

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?
include "../inc/config.php";
 
$filename = 'member250626.csv';
 
 
if (file_exists($filename)) {
    // fopen으로 읽기 모드로 엽니다
    if (($handle = fopen($filename"r")) !== FALSE) {
//        echo "<pre>"; // 보기 좋게 출력
        while (($data = fgetcsv($handle1000"|")) !== FALSE) {
            // $data는 한 줄을 배열로 반환합니다
            list($company$ceo$region$address$tel$fax= $data;
 
 
/*
            echo "회사명: $company\n";
            echo "대표자: $ceo\n";
            echo "지역: $region\n";
            echo "주소: $address\n";
            echo "전화번호: $tel\n";
            echo "팩스번호: $fax\n";
            echo "------------------------\n";
*/
 
                $company = addslashes($company);
                $ceo     = addslashes($ceo);
                $region  = addslashes($region);
                $address = addslashes($address);
                $tel = addslashes($tel);
                $fax = addslashes($fax);
            
 
            $query = "insert into company (area,com_name,dep,tel,fax,email,homepage,address1) values ('$region','$company','$ceo','$tel','$fax','','','$address')";
            mysqli_query($conn,$query) or die("error");
 
 
 
        }
//        echo "</pre>";
        
        fclose($handle);
    } else {
        echo "파일을 열 수 없습니다.";
    }
else {
    echo "파일이 존재하지 않습니다.";
}
 
?>
cs

 

 

 

Comments