Uploadify: passing form id as parameter using scriptData

I need the ability to have multiple boot inputs on the same page (potentially hundreds) using Uploadify. The PHP download file will rename the downloaded file based on the identifier of the enter button used to send it, so this identifier is required.

Since I will have hundreds of download buttons on one page, I would like to create a universal copy, so I did this using the form class, not the form identifier. However, when one of the inputs is pressed, I would like to pass the identifier of this input as scriptData for PHP. This does not work; PHP says that 'formId' is undefined.

Is there a good way to get the ID attribute of the form input used and pass it to downloadable PHP? Or is there a completely different and better way to achieve this? Thanks 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 are as follows:

<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" />
+3
source share
2 answers

It's good that I struggled with the same problem just a minute ago, and here is the solution, you can get the identifier of the element as a function definition in the onSelect event, as shown below

// EDIT Here is the working code

$('.uploady').uploadify({
    'uploader'  : '/uploadify/uploadify.swf',
    'script'    : '/uploadify/uploadify.php',
    'cancelImg' : '/uploadify/cancel.png',
    'folder'    : '/uploadify',
    'auto'      : true,
    // ANSWER
    'onSelect'    : function(event,ID,fileObj) {
        var elem_id = $(event.target).attr("id"); //here you get the id of the object.
        $("#"+elem_id).uploadifySettings('scriptData',{'formID':elem_id})
    },
});

now your formID will be sent correctly

+6
source

If you know that you want it to be sent every time (or not against sending it unnecessarily), you can do simple editing in the file Uploadify.js.

if ( 74 Uploadify v2.1.4):

if (settings.scriptData) {
    var scriptDataString = '';
    for (var name in settings.scriptData) {
        scriptDataString += '&' + name + '=' + settings.scriptData[name];
    }
    data.scriptData = escape(scriptDataString.substr(1));
}

:

if (settings.scriptData) {
    var scriptDataString = '';
    for (var name in settings.scriptData) {
        scriptDataString += '&' + name + '=' + settings.scriptData[name];
    }
}
scriptDataString += '&elemID=' + settings.id;
data.scriptData = escape(scriptDataString.substr(1));

scriptData:

$thisInputID = $_POST["elemID"];

ID ( elemID), scriptDataString += '&elemID=' + settings.id, .

0

Source: https://habr.com/ru/post/1781954/


All Articles