01.
<?
02.
session_start();
03.
if
(
$_SESSION
[
'UserID'
] ==
""
)
04.
{
05.
echo
"Please Login!"
;
06.
exit
();
07.
}
08.
ob_start();
09.
?>
10.
<html>
11.
<head>
12.
<title>Tutorial</title>
13.
14.
</head>
15.
<br>
16.
<body>
17.
<?
18.
19.
if
(((
$_FILES
[
"fileUpload"
][
"type"
] ==
"image/GIF"
)
20.
|| (
$_FILES
[
"fileUpload"
][
"type"
] ==
"image/JPEG"
)
21.
|| (
$_FILES
[
"fileUpload"
][
"type"
] ==
"image/PNG"
))
22.
&& (
$_FILES
[
"fileUpload"
][
"size"
] < 100000))
23.
{
24.
if
(
$_FILES
[
"fileUpload"
][
"error"
] > 0)
25.
{
26.
echo
"Return Code: "
.
$_FILES
[
"fileUpload"
][
"error"
] .
"<br />"
;
27.
}
28.
else
29.
{
30.
echo
"Upload: "
.
$_FILES
[
"fileUpload"
][
"name"
] .
"<br />"
;
31.
echo
"Type: "
.
$_FILES
[
"fileUpload"
][
"type"
] .
"<br />"
;
32.
echo
"Size: "
. (
$_FILES
[
"fileUpload"
][
"size"
] / 1024) .
" Kb<br />"
;
33.
echo
"Temp file: "
.
$_FILES
[
"fileUpload"
][
"tmp_name"
] .
"<br />"
;
34.
35.
if
(
file_exists
(
"myfile/"
.
$_FILES
[
"fileUpload"
][
"name"
]))
36.
{
37.
echo
$_FILES
[
"fileUpload"
][
"name"
] .
" already exists. "
;
38.
}
39.
else
40.
{
41.
move_uploaded_file(
$_FILES
[
"fileUpload"
][
"tmp_name"
],
42.
"myfile/"
.
$_FILES
[
"fileUpload"
][
"name"
]);
43.
echo
"Stored in: "
.
"myfile/"
.
$_FILES
[
"fileUpload"
][
"name"
];
44.
}
45.
}
46.
}
47.
else
48.
{
49.
echo
"Invalid file"
;
50.
51.
52.
$objConnect
= mysql_connect(
"localhost"
,
"root"
,
"6845"
)
or
die
(
"Error Connect to Database"
);
53.
$objDB
= mysql_select_db(
"dc"
);
54.
$Date
=
date
(
"d/m/y"
);
55.
$Time
=
date
(
"H:i:s"
);
56.
$strSQL
=
"INSERT INTO files "
;
57.
$strSQL
.=
"(UserID,Name,Date,Time,FilesName,Details,Name_M) VALUES ('"
.
$_POST
[
"UserID"
].
"','"
.
$_POST
[
"txtName"
].
"','$Date','$Time','"
.
$_FILES
[
"fileUpload"
][
"name"
].
"','"
.
$_POST
[
"details"
].
"','"
.
$_POST
[
"Name_M"
].
"')"
;
58.
$objQuery
= mysql_query(
$strSQL
);
59.
}
60.
?>
61.
<a href=
"index.php?page=ViewFiles"
>View files</a>