Copy Code code as follows:
<div id= "Mulitplefileuploader" >Upload</div>
<div id= "status" ></div>
<script>
$ (document). Ready (function ()
{
var settings = {
URL: "upload.php",
Method: "POST",
Allowedtypes: "Jpg,png,gif,doc,pdf,zip",
FileName: "MyFile",
Multiple:true,
Onsuccess:function (FILES,DATA,XHR)
{
$ ("#status"). HTML ("<font color= ' green ' >upload is success</font>");
},
Onerror:function (FILES,STATUS,ERRMSG)
{
$ ("#status"). HTML ("<font color= ' Red ' >upload is failed</font>");
}
}
$ ("#mulitplefileuploader"). UploadFile (settings);
});
</script>
upload.php
Copy Code code as follows:
<?php
If directory doesnot exists create it.
$output _dir = ". /upload ";
if (Isset ($_files["myfile"]))
{
$ret = Array ();
$error =$_files["MyFile" ["Error"];
{
if (!is_array ($_files["myfile"] [' name '])//single file
{
$fileName = $_files["MyFile"] ["name"];
Move_uploaded_file ($_files["myfile"] ["Tmp_name"], $output _dir "$_files["] ["name"]);
echo "<br> error:" $_files["myfile" ["Error"];
$ret [$fileName]= $output _dir. $fileName;
}
Else
{
$fileCount = count ($_files["myfile"] [' name ']);
for ($i =0; $i < $fileCount; $i + +)
{
$fileName = $_files["MyFile" ["Name"] [$i];
$ret [$fileName]= $output _dir. $fileName;
Move_uploaded_file ($_files["myfile"] ["tmp_name"] [$i], $output _dir. $fileName);
}
}
}
echo Json_encode ($ret);
}
?>