I created a custom ajax file uploader that functions perfectly with one instance on the page. However, I am currently facing an issue while trying to modify it to support multiple instances. When I attempt to upload multiple files using one form, the first file uploads successfully. But for all subsequent files, it redirects to the next file in line from the second form instance. Strangely, if I upload using the last (second) instance of the form, multiple files upload without any problems. The unique ID names are used consistently throughout the upload form and referenced in the JavaScript functions. Below are snippets of the relevant code:
The forms are dynamically generated by PHP with a randomly generated unique ID $uid
. First, the initialization of the upload function is output to the page within a <script>
tag:
'<script> '.
'jQuery(document).ready(function($){ '.
'var myup_'.$uid.' = new MyUp({ '.
// other settings being passed
}); '.
'}); '.
'</script>';
Similarly, the HTML form snippet includes the necessary input fields:
'<div class="myup_container" style="'.$inlinestyle.'">'.
'<form name="myup_form_'.$uid.'" id="myup_form_'.$uid.'" action="javascript:void(0);" enctype="multipart/form-data">'.
// more form elements
'</form>'.
// additional div elements as needed
'</div>';
More details can be found in the complete JavaScript segment posted above. If there's a straightforward solution to resolve this issue with multiple instances interfering with each other during file uploads, kindly provide your insights.