Uploadify: Passing a form's ID as a parameter with scriptData

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-12-24T06:50:44Z Indexed on 2010/12/24 6:54 UTC
Read the original article Hit count: 593

Filed under:
|

I need the ability to have multiple upload inputs on one page (potentially hundreds) using Uploadify. The upload PHP file will be renaming the uploaded file based on the ID of the input button used to submit it, so it will need that ID.

Since I will be having hundreds of upload buttons on one page, I wanted to create a universal instantiation, so I did this using the class of the forms rather than the ID of the forms. However, when one of the inputs is clicked, I would like to pass the ID of that input as scriptData to the PHP. This is not working; PHP says 'formId' is undefined.

Is there a good way get the ID attribute of the form input being used, and passing it to the upload PHP? Or is there a completely different and better method of accomplishing this? Thank you in advance!!

  <script type="text/javascript">
    $(document).ready(function() {
      $('.uploady').uploadify({
        'uploader'  : '/uploadify/uploadify.swf',
        'script'    : '/uploadify/uploadify.php',
        'cancelImg' : '/uploadify/cancel.png',
        'folder'    : '/uploadify',
        'auto'      : true,
      // LINE IN QUESTION
      'scriptData'  : {'formId':$(this).attr('id')}
  });
});
</script>
</head>

The inputs look like this:

<input id="file_upload1" class="uploady" name="file_upload" type="file" />
<input id="file_upload2" class="uploady" name="file_upload" type="file" />
<input id="file_upload3" class="uploady" name="file_upload" type="file" />

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about uploadify