01.
<html>
02.
<head>
03.
<title></title>
04.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
05.
</head>
06.
<body>
07.
<?
08.
09.
10.
include
(
"../../system_connecttion/connection.php"
);
11.
12.
$txtStuGID
=
$_POST
[
"txtStuGID"
];
13.
$txtStuGName
=
$_POST
[
"txtStuGName"
];
14.
$StuGFile
=
$_FILES
[
"StuGFile"
][
"name"
];
15.
$txtStuGFile
=
$_POST
[
"txtStuGFile"
];
16.
17.
$type
=
explode
(
"."
,
$txtStuGFile
);
18.
print
$type
[1].
"<br>"
;
19.
20.
21.
if
((
$type
[1]!=
"csv"
)
and
(
$type
[1]!=
"xls"
)
and
(
$type
[1]!=
"xlsx"
)){
22.
print
"<script>alert('ERROR : ไม่รู้จักไฟล์นามสกุล .$type[1] ที่คุณเลือก')</script>"
;
23.
print
"<script language='javascript'>javascript:history.back(1);</script>"
;
24.
exit
();
25.
}
26.
27.
28.
if
(
$txtStuGFile
!=
""
){
29.
30.
$alumnidoc
=
$txtStuGName
.
"."
.
$type
[1];
31.
print
$alumnidoc
.
"<br>"
;
32.
33.
move_uploaded_file(
$_FILES
[
"StuGFile"
][
"tmp_name"
],
"../../upload/fileupload/"
.
$alumnidoc
);
34.
35.
$objCSV
=
fopen
(
$_FILES
[
"StuGFile"
][
"name"
],
"r"
);
36.
while
((
$objArr
=
fgetcsv
(
$objCSV
, 1000,
","
)) !== FALSE) {
37.
$strSQL
=
"INSERT INTO tb_alumnidetail"
;
38.
$strSQL
.=
"(IDCard,FName,LName,Brithday,YearAdmission,ProvinceID) "
;
39.
$strSQL
.=
"VALUES "
;
40.
$strSQL
.=
"('"
.
$objArr
[3].
"','"
.
$objArr
[5].
"','"
.
$objArr
[6].
"' "
;
41.
$strSQL
.=
",'"
.
$objArr
[8].
"','"
.
$objArr
[11].
"','"
.
$objArr
[9].
"') "
;
42.
$objQuery
= mysql_query(
$strSQL
);
43.
}
44.
45.
fclose(
$objCSV
);
46.
47.
echo
"Upload & Import Done."
;
48.
49.
}
50.
?>
51.
52.
</body>
53.
</html>