01.
if
(trim(
$_FILES
[
"fileUpload"
][
"tmp_name"
]) ==
""
){
02.
03.
/
04.
05.
echo
"<script language=\"JavaScript\">"
;
06.
echo
"alert('Insert Complete');"
;
07.
echo
"window.location='product.php';"
;
08.
echo
"</script>"
;
09.
10.
}
else
if
(trim(
$_FILES
[
"fileUpload"
][
"tmp_name"
]) !=
""
){
11.
12.
$images
=
$_FILES
[
"fileUpload"
][
"tmp_name"
];
13.
$images_file
=
$_FILES
[
"fileUpload"
][
"type"
];
14.
$images_time
=
date
(
'dmYHis'
);
15.
srand((double)microtime()*1000000);
16.
$Pic_name
=
$random_pic
= rand(1,9999999);
17.
if
(
$images_file
==
"image/gif"
)
18.
{
19.
$filename
=
$Pic_name
.
".gif"
;
20.
}
21.
if
((
$images_file
==
"image/jpg"
)||(
$images_file
==
"image/jpeg"
)||(
$images_file
==
"image/pjpeg"
))
22.
{
23.
$filename
=
$Pic_name
.
".jpg"
;
24.
}
25.
$new_images
=
"$images_time"
.
"$filename"
;
26.
27.
28.
$width
=500;
29.
$size
=
GetimageSize
(
$images
);
30.
$height
=
round
(
$width
*
$size
[1]/
$size
[0]);
31.
if
(
$images_file
==
"image/gif"
)
32.
{
33.
$images_orig
= ImageCreateFromGIF(
$images
);
34.
}
35.
if
((
$images_file
==
"image/jpg"
)||(
$images_file
==
"image/jpeg"
)||(
$images_file
==
"image/pjpeg"
))
36.
{
37.
$images_orig
= ImageCreateFromJPEG(
$images
);
38.
}
39.
40.
41.
$file
=
$_FILES
[
"fileUpload"
][
"type"
];
42.
if
((
$file
!=
"image/jpg"
)
and
(
$file
!=
"image/jpeg"
)
and
(
$file
!=
"image/pjpeg"
)
and
(
$file
!=
"image/gif"
))
43.
{
44.
echo
"<script language='JavaScript'>"
;
45.
echo
"alert('ไฟล์รูปภาพไม่ถูกต้อง (ใช้ได้เฉพาะ jpg,jpeg,pjpeg,gif เท่านั้น)');"
;
46.
echo
"window.location='bf_product_add.php';"
;
47.
echo
"</script>"
;
48.
}
49.
else
if
((
$file
==
"image/jpg"
)
or
(
$file
==
"image/jpeg"
)
or
(
$file
==
"image/pjpeg"
)
or
(
$file
==
"image/gif"
))
50.
{
51.
52.
53.
54.
$photoX
= ImagesX(
$images_orig
);
55.
$photoY
= ImagesY(
$images_orig
);
56.
$images_fin
= ImageCreateTrueColor(
$width
,
$height
);
57.
ImageCopyResampled(
$images_fin
,
$images_orig
, 0, 0, 0, 0,
$width
+1,
$height
+1,
$photoX
,
$photoY
);
58.
ImageGIF(
$images_fin
,
"../images/products/"
.
$new_images
);
59.
ImageJPEG(
$images_fin
,
"../images/products/"
.
$new_images
);
60.
ImageDestroy(
$images_orig
);
61.
ImageDestroy(
$images_fin
);
62.
63.
/
64.
65.
66.
$strSQL
=
"UPDATE product"
;
67.
$strSQL
.=
" SET pro_pic = '"
.
$new_images
.
"' WHERE pro_name = '$_POST[pro_name]'"
;
68.
$objQuery
= mysql_query(
$strSQL
);
69.
70.
echo
"<script language=\"JavaScript\">"
;
71.
echo
"alert('Insert Complete');"
;
72.
echo
"window.location='product.php';"
;
73.
echo
"</script>"
;
74.
75.
}
76.
77.
}