Click here to view Demo
File uploads can be added dynamically. Before files get uploaded ,inputs will be checked against duplicates.
(Here the file just copy to the folder,this post is mainly targeted duplicate validation)
file/folder structure
-upload(folder,this folder should be writable)
-upload.php
-upload.js
A folder named 'upload' is created and it should have read/write permission.
upload.php
<html>
<head>
<script language="javascript" src="upload.js">
</script>
</head>
<body>
<form name="frmUpload" method="post" enctype="multipart/form-data" onSubmit="return validateFiles();" action="">
<table>
<thead>
</thead>
<tbody>
<tr>
<td>
Select File <span id="star">*</span> :
</td>
<td>
<input type="file" name="file0" id="file0" />
<a onClick="addElement();" href="#" >Add more Files</a>
<div id="divfile0"></div>
</td>
</tr>
<tr>
<div id="theValue">
<input type="hidden" id="hdn" name="hdn" value="0"/>
<td></td>
<td>
<div id="myDiv">
</div>
</div>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="btnSubmit" id="btnSubmit" value="Add"/><input type="reset" name="btnReset" id="btnReset" value="Reset" onclick="clearDiv()"/></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['btnSubmit'])) {
$hdn = $_REQUEST['hdn'] + 1;
for($i=0;$i<=$hdn;$i++) {
$current_image = $_FILES['file'.$i]['name'];
chmod("uploads",0777);
$destination="uploads/".$current_image;
$action = copy($_FILES['file'.$i]['tmp_name'], $destination);
}
echo "Uploaded";
?>
<script>
setTimeout("location.href = 'upload.php';",1000);
</script>
<?php
}
?>
upload.js
function validateFiles()
{
var error =0;
var fieldNames = new Array();
var searchFieldNames=new Array();
var numFile = parseInt(document.getElementById('hdn').value) + 1;
for(var i=0;i<numFile;i++){
var fileId = 'file'+i;
fieldNames[i] = document.getElementById(fileId).value;
searchFieldNames[i]=document.getElementById(fileId).value;
document.getElementById('divfile'+i).innerHTML ="";
}
for(var a=0;a<fieldNames.length;a++){
var string=fieldNames[a];
for (var i = 0; i < fieldNames.length; i++)
{
if(fieldNames[i] != ''){
if((fieldNames[i] == string) && (a!=i))
{
document.getElementById('divfile'+i).innerHTML ="Duplicate File";
error = error+1;
}
}
}
}
if(error>0){
return false;
}
}
function addElement() {
var setId = 0;
var hdnId = document.getElementById('hdn');
var newId = parseInt(hdnId.value) + 1;
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value -1)+ 2;
numi.value = num;
var hide = document.createElement('input');
hide.setAttribute("type", "file");
hide.setAttribute("id", 'file'+newId);
hide.setAttribute("name", 'file'+newId);
var td = document.createElement('td');
var divs = document.createElement('div');
divs.setAttribute("id", 'divfile'+newId);
divs.setAttribute("name", 'divfile'+newId);
ni.appendChild(hide);
ni.appendChild(td);
td.appendChild(divs);
hdnId.value = parseInt(hdnId.value)+1;
}
30 Comments
I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success.
ReplyDeleteI can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success.
ReplyDeletedont know whether the same person..bvut the same comment as above..anyway thanks :P :)
ReplyDeletethank you.. :) :)
ReplyDeleteI truly loved this brilliant article. Please continue this awesome work. Regards, Duyq.
ReplyDeleteSearching for this for some time now - i guess luck is more advanced than search engines :)
ReplyDeleteSuch a well written post.. Thnkx for sharing this post!
ReplyDeleteIt’s the first time I have heard that in Macedonia, obits are an unusual observe. You have wonderfully written the post. I have liked your way of writing this. Thanks for sharing this.
ReplyDeleteHey admin, very informative blog post! Pleasee continue this awesome work..
ReplyDeletethaaaaank you.. :)
ReplyDeleteyes..I dont like to read long descriptions..So i hope that others also same..Thats why my blog posts are short and sweet.. :) thanks.. :)
ReplyDeleteyes..You are lucky to find my blog.. :P :D he he.. Thank you for your comment.. :)
ReplyDeleteThank you very much for your feedback.. :)
ReplyDeleteyes..I dont like to read long descriptions..So i hope that others also same..Thats why my blog posts are short and sweet.. :) thank you for your comment.. :)
ReplyDeleteI like your site.
ReplyDeletethank you .. :)
ReplyDeleteI’ve been visiting your blog for a while now and I always find a gem in your new posts. Thanks for sharing.
ReplyDeletezk4uKe zmbsjfgimyup, [url=http://idaafgchbyjb.com/]idaafgchbyjb[/url], [link=http://ftkjqegajrxm.com/]ftkjqegajrxm[/link], http://mcpptjoelxwg.com/
ReplyDeletezjiW3s sxxrrnodbxst, [url=http://iajmpmuhfxcd.com/]iajmpmuhfxcd[/url], [link=http://rqmclgnwgxvc.com/]rqmclgnwgxvc[/link], http://nbzufgydtbxv.com/
ReplyDeleteSli4n3 ycyxjsmznkdm, [url=http://bcffouqtrymx.com/]bcffouqtrymx[/url], [link=http://hupvxnlhfxry.com/]hupvxnlhfxry[/link], http://ynmmsrgtpime.com/
ReplyDelete473hIW dhdkgqphajwn, [url=http://jflemhqjdrwc.com/]jflemhqjdrwc[/url], [link=http://mlyfkpuoxsrd.com/]mlyfkpuoxsrd[/link], http://gcvcdzvtkbkb.com/
ReplyDelete8L4Ee0 kydykhhaghaf, [url=http://kgcxcfcdmmtm.com/]kgcxcfcdmmtm[/url], [link=http://feurfvfwhblz.com/]feurfvfwhblz[/link], http://swtqjclbdbqo.com/
ReplyDeleteYou, my friend, ROCK! I found exactly the info I already searched everywhere and just could not find it. What an ideal website.
ReplyDeleteThank You For This Post, was added to my bookmarks.
ReplyDeleteThanks for a very interesting site. What else may I get that kind of info written in such a perfect means? I have a mission that I am simply now running on, and I have been at the look out for such info.
ReplyDeleteGood post. I’m a normal visitor of your site and appreciate you taking the time to maintain the excellent site. I will be a regular visitor for a long time.
ReplyDeleteI truly appreciate your post. I’ve been looking everywhere for this! Thank goodness I found it on Google. You've made my week! Thank you again.. :^)
ReplyDeleteTerrific, this information is exactly what I was searching for.
ReplyDeleteI’ve been visiting your blog for a while now and I always find a gem in your new posts. Thanks for sharing.
ReplyDeleteVery Interesting Blog! Thank You For Thi Post!
ReplyDeletePost a Comment