HTML
<
form
method
=
"post"
enctype
=
"multipart/form-data"
name
=
"formUploadFile"
>
<
label
>Select files for upload:</
label
>
<
input
type
=
"file"
name
=
"files[]"
multiple
=
"multiple"
/>
<
input
type
=
"submit"
value
=
"Upload Files"
name
=
"btnSubmit"
/>
</
form
>
PHP
$errors
=
array
();
$uploadedFiles
=
array
();
$extension
=
array
(
"jpeg"
,
"jpg"
,
"png"
,
"gif"
);
$bytes
= 1024;
$KB
= 1024;
$totalBytes
=
$bytes
*
$KB
;
$UploadFolder
=
"UploadFolders"
;
$counter
= 0;
foreach
(
$_FILES
[
"files"
][
"tmp_name"
]
as
$key
=>
$tmp_name
){
$temp
=
$_FILES
[
"files"
][
"tmp_name"
][
$key
];
$name
=
$_FILES
[
"files"
][
"name"
][
$key
];
if
(
empty
(
$temp
))
{
break
;
}
$counter
++;
$UploadOk
= true;
if
(
$_FILES
[
"files"
][
"size"
][
$key
] >
$totalBytes
)
{
$UploadOk
= false;
array_push
(
$errors
,
$name
.
" file size is larger than the 1 MB."
);
}
$ext
=
pathinfo
(
$name
, PATHINFO_EXTENSION);
if
(in_array(
$ext
,
$extension
) == false){
$UploadOk
= false;
array_push
(
$errors
,
$name
.
" is invalid file type."
);
}
if
(
file_exists
(
$UploadFolder
.
"/"
.
$name
) == true){
$UploadOk
= false;
array_push
(
$errors
,
$name
.
" file is already exist."
);
}
if
(
$UploadOk
== true){
move_uploaded_file(
$temp
,
$UploadFolder
.
"/"
.
$name
);
array_push
(
$uploadedFiles
,
$name
);
}
}
if
(
$counter
>0){
if
(
count
(
$errors
)>0)
{
echo
"Errors:"
;
echo
"
"
;
foreach
(
$errors
as
$error
)
{
echo
"
"
.
$error
.
"
;
}
echo
"
"
;
}
if
(
count
(
$uploadedFiles
)>0){
echo
"Uploaded Files:"
;
echo
"
"
;
foreach
(
$uploadedFiles
as
$fileName
)
{
echo
"
"
.
$fileName
.
"
;
}
echo
"
"
;
echo
count
(
$uploadedFiles
).
" file(s) are successfully uploaded."
;
}
}
else
{
echo
"Please, Select file to upload."
;
}