Please help me in creating a multiple file upload and then process it in ajax so that it can view into the page before the form is submitted

this is my form

<form name="create_memo" method="post" ENCTYPE="multipart/form-data">
<input id = "memofile" type="file" name="img[]" onchange="uploader();" multiple />
<input type="submit">
</form>

<div id="memoupload">
</div>

this is the javascript

function upload()
{
var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }


xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("memoupload").innerHTML=xmlhttp.responseText;
    }
  }

  var file = document.getElementById('memofile').value;

xmlhttp.open("GET","uploadmemo.php?file="+file,true);
xmlhttp.send();
}

php file

i have to count the file in img[] file and upload it into database.
<?php
$file=$_GET['img']['name'];
echo count('$file');
?>

please help me.. i dont know how to initiate this..

Thanks in advance..

Recommended Answers

All 2 Replies

take a look at the jquery ajax. far fewer lines of code. it would then allow you to make multiple instances of a file upload option like "upload another file".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.