01.
<?
02.
mysql_connect(
"localhost"
,
"root"
,
"1234"
);
03.
mysql_select_db(
"assets"
);
04.
mysql_query(
"SET NAMES UTF8"
);
05.
$today
=
date
(
"Y-m-d H:i:s"
);
06.
07.
if
(
$_POST
[
'id'
]!=
""
){
08.
09.
$response
=
""
;
10.
$save_path
=
""
;
11.
12.
if
(
$_FILES
[
'pic_file'
][
'error'
]!=0) {
13.
$response
=
"Error: {$_FILES['upfile']['error']}"
;
14.
}
15.
else
{
16.
$accept_types
=
array
(
"image/gif"
,
"image/jpeg"
,
"image/pjpeg"
,
17.
"image/png"
,
"image/x-png"
);
18.
19.
$type
=
$_FILES
[
'pic_file'
][
'type'
];
20.
if
(!in_array(
$type
,
$accept_types
)) {
21.
$response
.=
"��ͧ������쪹Դ .gif, .jpeg, .jpg ���� .png ���ҹ���<br>"
;
22.
}
23.
else
{
24.
$save_dir
=
"uploads"
;
25.
if
(!
file_exists
(
$save_dir
)) {
26.
mkdir
(
$save_dir
);
27.
}
28.
$save_path
=
$save_dir
.
"/"
.
$_FILES
[
'pic_file'
][
'name'
];
29.
30.
if
(!move_uploaded_file(
$_FILES
[
'pic_file'
][
'tmp_name'
],
$save_path
)) {
31.
$response
.=
"Move Failed!"
;
32.
}
33.
}
34.
}
35.
if
(
$_FILES
[
'pic_file'
][
'name'
]!=
""
)
36.
{
37.
$strSQL
=
"update computer set comtype='"
.
$_POST
[
"comtype"
].
"',lastupdate='"
.
$today
.
"',code='"
.
$_POST
[
"code"
].
"',name='"
.
$_POST
[
"name"
].
"',serial_num='"
.
$_POST
[
"serial_num"
].
"',team_id='"
.
$_POST
[
"team_id"
].
"',depart_id='"
.
$_POST
[
"depart_id"
].
"',ip='"
.
$_POST
[
"ip"
].
"',brand='"
.
$_POST
[
"brand"
].
"',cpu='"
.
$_POST
[
"cpu"
].
"',mb='"
.
$_POST
[
"mb"
].
"',vga='"
.
$_POST
[
"vga"
].
"',ram='"
.
$_POST
[
"ram"
].
"',hd='"
.
$_POST
[
"hd"
].
"',lancard='"
.
$_POST
[
"lancard"
].
"',cdrom='"
.
$_POST
[
"cdrom"
].
"',monitor='"
.
$_POST
[
"monitor"
].
"',mouse='"
.
$_POST
[
"mouse"
].
"',price='"
.
$_POST
[
"price"
].
"',pdate='"
.
$_POST
[
"pdate"
].
"',detail='"
.
$_POST
[
"detail"
].
"',software='"
.
$_POST
[
"software"
].
"',pic_file='"
.
$_FILES
['pic_file
']['
name
']."'
,os=
'".$_POST["os"]."'
,product_id=
'".$_POST["product_id"]."'
,vendor=
'".$_POST["vendor"]."'
,expdate=
'".$_POST["expdate"]."'
,state=
'".$_POST["state"]."'
where id=
'".$_POST["id"]."'
";
38.
$objQuery
= mysql_query(
$strSQL
);
39.
header(
"location:index.php?0"
);
40.
}
else
41.
{
42.
$strSQL
=
"update computer set comtype='"
.
$_POST
[
"comtype"
].
"',lastupdate='"
.
$today
.
"',code='"
.
$_POST
[
"code"
].
"',name='"
.
$_POST
[
"name"
].
"',serial_num='"
.
$_POST
[
"serial_num"
].
"',team_id='"
.
$_POST
[
"team_id"
].
"',depart_id='"
.
$_POST
[
"depart_id"
].
"',ip='"
.
$_POST
[
"ip"
].
"',brand='"
.
$_POST
[
"brand"
].
"',cpu='"
.
$_POST
[
"cpu"
].
"',mb='"
.
$_POST
[
"mb"
].
"',vga='"
.
$_POST
[
"vga"
].
"',ram='"
.
$_POST
[
"ram"
].
"',hd='"
.
$_POST
[
"hd"
].
"',lancard='"
.
$_POST
[
"lancard"
].
"',cdrom='"
.
$_POST
[
"cdrom"
].
"',monitor='"
.
$_POST
[
"monitor"
].
"',mouse='"
.
$_POST
[
"mouse"
].
"',price='"
.
$_POST
[
"price"
].
"',pdate='"
.
$_POST
[
"pdate"
].
"',detail='"
.
$_POST
[
"detail"
].
"',software='"
.
$_POST
[
"software"
].
"',os='"
.
$_POST
[
"os"
].
"',product_id='"
.
$_POST
[
"product_id"
].
"',vendor='"
.
$_POST
[
"vendor"
].
"',expdate='"
.
$_POST
[
"expdate"
].
"',state='"
.
$_POST
[
"state"
].
"' where id='"
.
$_POST
[
"id"
].
"'"
;
43.
$objQuery
= mysql_query(
$strSQL
);
44.
header(
"location:index.php?0"
);
45.
46.
}
47.
48.
}
else
49.
{
50.
51.
$response
=
""
;
52.
$save_path
=
""
;
53.
54.
if
(
$_FILES
[
'pic_file'
][
'error'
]!=0) {
55.
$response
=
"Error: {$_FILES['upfile']['error']}"
;
56.
}
57.
else
{
58.
$accept_types
=
array
(
"image/gif"
,
"image/jpeg"
,
"image/pjpeg"
,
59.
"image/png"
,
"image/x-png"
);
60.
61.
$type
=
$_FILES
[
'pic_file'
][
'type'
];
62.
if
(!in_array(
$type
,
$accept_types
)) {
63.
$response
.=
"��ͧ������쪹Դ .gif, .jpeg, .jpg ���� .png ���ҹ���<br>"
;
64.
}
65.
else
{
66.
$save_dir
=
"uploads"
;
67.
if
(!
file_exists
(
$save_dir
)) {
68.
mkdir
(
$save_dir
);
69.
}
70.
$save_path
=
$save_dir
.
"/"
.
$_FILES
[
'pic_file'
][
'name'
];
71.
72.
if
(!move_uploaded_file(
$_FILES
[
'pic_file'
][
'tmp_name'
],
$save_path
)) {
73.
$response
.=
"Move Failed!"
;
74.
}
75.
}
76.
}
77.
78.
79.
$strSQL
=
"INSERT INTO computer (comtype,lastupdate,code,name,serial_num,team_id,depart_id,ip,brand,cpu,mb,vga,ram,hd,lancard,cdrom,monitor,mouse,price,pdate,detail,software,pic_file,os,product_id,vendor,expdate,state) VALUES ('"
.
$_POST
[
"comtype"
].
"','"
.
$today
.
"','"
.
$_POST
[
"code"
].
"','"
.
$_POST
[
"name"
].
"','"
.
$_POST
[
"serial_num"
].
"','"
.
$_POST
[
"team_id"
].
"','"
.
$_POST
[
"depart_id"
].
"','"
.
$_POST
[
"ip"
].
"','"
.
$_POST
[
"brand"
].
"','"
.
$_POST
[
"cpu"
].
"','"
.
$_POST
[
"mb"
].
"','"
.
$_POST
[
"vga"
].
"','"
.
$_POST
[
"ram"
].
"','"
.
$_POST
[
"hd"
].
"','"
.
$_POST
[
"lancard"
].
"','"
.
$_POST
[
"cdrom"
].
"','"
.
$_POST
[
"monitor"
].
"','"
.
$_POST
[
"mouse"
].
"','"
.
$_POST
[
"price"
].
"','"
.
$_POST
[
"pdate"
].
"','"
.
$_POST
[
"detail"
].
"','"
.
$_POST
[
"software"
].
"','"
.
$_FILES
['pic_file
']['
name
']."'
,
'".$_POST["os"]."'
,
'".$_POST["product_id"]."'
,
'".$_POST["vendor"]."'
,
'".$_POST["expdate"]."'
,
'".$_POST["state"]."'
)";
80.
$objQuery
= mysql_query(
$strSQL
);
81.
82.
header(
"location:index.php"
);
83.
84.
}
85.
86.
87.
88.
?>