01.
<html>
02.
<head>
03.
<title>ThaiCreate.Com PHP Upload Resize to MySQL</title>
04.
</head>
05.
<body>
06.
<?php
07.
if
(trim(
$_FILES
[
"fileUpload"
][
"tmp_name"
]) !=
""
)
08.
{
09.
$images
=
$_FILES
[
"fileUpload"
][
"tmp_name"
];
10.
$new_images
=
"Thumbnails_"
.
$_FILES
[
"fileUpload"
][
"name"
];
11.
copy
(
$_FILES
[
"fileUpload"
][
"tmp_name"
],
"MyResize/"
.
$_FILES
[
"fileUpload"
][
"name"
]);
12.
$width
=100;
13.
$size
=
GetimageSize
(
$images
);
14.
$height
=
round
(
$width
*
$size
[1]/
$size
[0]);
15.
$images_orig
= ImageCreateFromJPEG(
$images
);
16.
$photoX
= ImagesX(
$images_orig
);
17.
$photoY
= ImagesY(
$images_orig
);
18.
$images_fin
= ImageCreateTrueColor(
$width
,
$height
);
19.
ImageCopyResampled(
$images_fin
,
$images_orig
, 0, 0, 0, 0,
$width
+1,
$height
+1,
$photoX
,
$photoY
);
20.
ImageJPEG(
$images_fin
,
"MyResize/"
.
$new_images
);
21.
ImageDestroy(
$images_orig
);
22.
ImageDestroy(
$images_fin
);
23.
24.
echo
"Resize Successful.<br>"
;
25.
26.
27.
$objConnect
= mysql_connect(
"localhost"
,
"root"
,
"root"
)
or
die
(
"Error Connect to Database"
);
28.
$objDB
= mysql_select_db(
"mydatabase"
);
29.
$strSQL
=
"INSERT INTO files "
;
30.
$strSQL
.=
"(Thumbnails,FilesName) VALUES ('"
.
$new_images
.
"','"
.
$_FILES
[
"fileUpload"
][
"name"
].
"')"
;
31.
$objQuery
= mysql_query(
$strSQL
);
32.
}
33.
34.
?>
35.
<a href=
"phpUploadResizeToMySQL3.php"
>View files</a>
36.
</body>
37.
</html>