Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Script to create multiple input type file in JavaScript
WhatsApp
Vinod Verma
Nov 19
2014
1.8
k
0
1
upload image.zip
<?php
$getuploadfiles
=
""
;
$validExtensions
=
array
(
".gif"
,
".jpeg"
,
".jpg"
,
".png"
,
".GIF"
,
".JPEG"
,
".JPG"
,
".PNG"
,
".SWF"
,
".swf"
);
for
(
$i
=0;
$i
<=
count
(
$_FILES
[
"file"
][
"name"
])-1;
$i
++)
{
$filename
=
$_FILES
[
"file"
][
"tmp_name"
][
$i
];
$fileExtension
=
strrchr
(
$_FILES
[
'file'
][
'name'
][
$i
],
"."
);
if
(in_array(
$fileExtension
,
$validExtensions
))
{
$newName
= time() .
'_'
.
$_FILES
[
'file'
][
'name'
][
$i
];
$destination
=
'RealImage/'
.
$newName
;
if
(move_uploaded_file(
$_FILES
[
'file'
][
'tmp_name'
][
$i
],
$destination
))
{
$getuploadfiles
=
$getuploadfiles
.
$newName
.
','
;
}
}
}
?>
<script type=
"text/javascript"
src=
"jquery2.js"
></script>
<script>
$(
function
(){
var
i=1;
$(
'#addupload'
).click(
function
(){
if
(i<=9)
{
var
addControl =
'<br><br><label>Upload an image:</label>'
;
addControl +=
' <input type="file" name="file[]" class="imageupload"><br>'
;
$(
'#TillHere'
).before(addControl);
i=i+1; $(
'#TillHere'
).focus();
}
});
});
</script>
<label>Upload an image:</label> <input type=
"file"
name=
"file[]"
class
=
"imageupload"
onchange=
"readURL(this);"
><span id=
"addupload"
>Add more images</span>
<div
class
=
"Bottom-line"
id=
"TillHere"
></div>
upload multiple image by using add more option.
Up Next
Script to create multiple input type file in JavaScript