批量上传php图片只上传2或3张图片

The following code I am using from another example, when executing it runs and succeeds without error, if I select 6 or 8 photos from camera roll on iPhone (safari browser) its shoes progress and upload of all 6 or 8 images. in the uploads directory it seems to only have 2 or 3 images.

I originally thought the random time line was running faster than a millisecond and maybe the encryption was producing the exact same string but now I'm not sure??? Unfortunately the file name seems to be the same name on all images its getting from the iPhone in Camera Roll??? "Image.jpeg"

REVISED RESULTS: this error only occurs on a mobile iPhone browser? when run on desktop the file names are appended to front of image name, and actual image names appear in html results, on iPhone browser the image names in html page are all image.jpeg not the actual image name???

<?php
//If directory doesnot exists create it.
$output_dir = "uploads/";

if(isset($_FILES["myfile"]))
{
$ret = array();

$error =$_FILES["myfile"]["error"];
{

    if(!is_array($_FILES["myfile"]['name'])) //single file
    {
        $RandomNum   = md5(date('Y-m-d H:i:s:u'));

        $ImageName      = str_replace(' ','-',strtolower($_FILES['myfile']['name']));
        $ImageType      = $_FILES['myfile']['type']; //"image/png", image/jpeg etc.

        $ImageExt = substr($ImageName, strrpos($ImageName, '.'));
        $ImageExt       = str_replace('.','',$ImageExt);
        $ImageName      = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);
        //$NewImageName = $ImageName.'-'.$RandomNum.'.'.$ImageExt;
        $NewImageName = $RandomNum.'.'.$ImageExt;

        move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $NewImageName);
        echo "<br> Error: ".$_FILES["myfile"]["error"];

             $ret[$fileName]= $output_dir.$NewImageName;
    }
    else
    {
        $fileCount = count($_FILES["myfile"]['name']);
        for($i=0; $i < $fileCount; $i++)
        {
            $RandomNum   = md5(date('Y-m-d H:i:s:u'));

            $ImageName      = str_replace(' ','-',strtolower($_FILES['myfile']['name'][$i]));
            $ImageType      = $_FILES['myfile']['type'][$i]; //"image/png", image/jpeg etc.

            $ImageExt = substr($ImageName, strrpos($ImageName, '.'));
            $ImageExt       = str_replace('.','',$ImageExt);
            $ImageName      = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);
            //$NewImageName = $ImageName.'-'.$RandomNum.'.'.$ImageExt;
            $NewImageName = $RandomNum.'.'.$ImageExt;

            $ret[$NewImageName]= $output_dir.$NewImageName;
            move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$NewImageName );
        }
    }
}
echo json_encode($ret);

}

?> 

HTML:

<script>

$(document).ready(function()
{

var settings = {
  url: "upload.php",
  method: "POST",
  allowedTypes:"jpg,png,gif,doc,pdf,zip,jpeg",
  fileName: "myfile",
  multiple: true,
  onSuccess:function(files,data,xhr)
  {
    $("#status").html("<font color='green'>Upload is success</font>");

  },
afterUploadAll:function()
  {
    alert("all images uploaded!!");
  },
onError: function(files,status,errMsg)
  {     
    $("#status").html("<font color='red'>Upload is Failed</font>");
  }
}
$("#mulitplefileuploader").uploadFile(settings);

});
</script>