Problem sending additional post data to server with uploadify

前端 未结 2 938
萌比男神i
萌比男神i 2021-01-16 02:52

I\'m using uploadify on a page that allows a user to upload images as well as a category field in which to send those images. Now, I see that uploadify provides a \"scriptDa

相关标签:
2条回答
  • 2021-01-16 03:12

    you would need to fetch the current state of the user's input via one of uploadify's callback hoock: onOpen or onSelect . See their documentation for the right one. I guess onOpen is more reliable as it will check the current state of user input everytime an upload is started. Still, you might need to disable other user inputs while an upload is ongoing, or still require the user to submit the form, otherwise any user input done after the last upload has started will be lost.

    Anyway, I found this on their forum, which i would put on a onOpen callback:

    $('#fileInput2').uploadifySettings(
    'scriptData', 
    {'ext':$('#dirTimeStamp').val(), 'ext2':$('#txtEmail').val()}
    );
    

    A final implementation would be (using the demo code) :

    <input id="fileInput" name="fileInput" type="file" />
    <script type="text/javascript">// <![CDATA[
    $(document).ready(function() {
    $('#fileInput').uploadify({
    'uploader'  : 'uploadify.swf',
    'script'    : 'uploadify.php',
    'cancelImg' : 'cancel.png',
    'auto'      : true,
    'folder'    : '/uploads',
    'onOpen' : function(){
    $('#fileInput').uploadifySettings(
        'scriptData', 
        {'ext':$('#dirTimeStamp').val(), 'ext2':$('#txtEmail').val()}
        );
    }
    });
    });
    // ]]></script>
    
    0 讨论(0)
  • 2021-01-16 03:13

    Beside put the code to update the scriptData inside onOpen, you can also do it before starting upload. This can be done if you set auto to false, so you will need to call uploadifyUpload() manually.

    Take a look at accepted answers in this thread.

    0 讨论(0)
提交回复
热议问题