4

The problem below is that when the function is initiated, of course, MyInputVariable is empty.

<?php $timestamp = time();?>
$(function () {
    $('#file_upload').uploadifive({
        'auto': false,
        'dnd': true,
        'checkScript': 'check-exists.php',
        'formData': {
            'timestamp': '<?php echo $timestamp;?>',
            'token': '<?php echo md5('unique_salt' . $timestamp);?>',
            'MyNumber': $('#MyInputVariable').val(),
        },
        'queueID': 'queue',
        'uploadScript': 'upload.php',
        'onUploadComplete': function(file, data) {console.log(data);}
    });
});

There must be a way to instigate onUpload, onUploadComplete, onUploadFile or something to update formData, but I am at a loss as to how to do that.


Please note that this is uploadiFIVE, not uploadify. The functions/methods differ significantly, and solutions will probably not apply to both.

2 Answers 2

8

After many hours of experimentation with misleading solutions on the uplodifive forum, this is the solution.

In your HTML anchor tag:

<input id="file_upload" name="file_upload" type="file" multiple="true">
<a style="position: relative; top: 8px;" href="javascript:$('#file_upload').uploadifive('upload')">Upload Files</a>

Change the anchor tag to:

<a style="position: relative; top: 8px;" href="javascript:uploadFiles();">Upload Files</a>

Completely eliminate the formData setting from the initial function call so it then looks something like this:

$(function()
{
    $('#file_upload').uploadifive(
    {
        'auto'               : false,
        'dnd'                : true,
        'checkScript'        : 'check-exists.php',
        'queueID'            : 'queue',
        'uploadScript'       : 'upload.php',
        'onUploadComplete'   : function(file, data) {console.log(data);}
    });
});

Than add this function:

   function uploadFiles()
   {
      $('#file_upload').data('uploadifive').settings.formData =
      {
         'timestamp' : '<?php echo $timestamp;?>',
         'token'     : '<?php echo md5('unique_salt' . $timestamp);?>',
         'MyNumber'  : $('#MyInputVariable').val()
      },
      $('#file_upload').uploadifive('upload');
   }

And whatever other variables you need to add. Your input variables will now post on upload.

Sign up to request clarification or add additional context in comments.

1 Comment

Any suggestions to make auto upload (auto=true)? it works only when auto is set to false and click on the link to call the upload function
5

I think this is best anwser

How to submit dynamic variables with uploadifive

replace this:

'formData': {
        'timestamp': '<?php echo $timestamp;?>',
        'token': '<?php echo md5('unique_salt' . $timestamp);?>',
        'MyNumber': $('#MyInputVariable').val(),
    },

by this:

'onUpload' : function(){
$('#file_upload').data('uploadifive').settings.formData = {
        'timestamp': '<?php echo $timestamp;?>',
        'token': '<?php echo md5('unique_salt' . $timestamp);?>',
        'MyNumber': $('#MyInputVariable').val(),
}},

and this is full code:

<?php $timestamp = time();?>
$(function () {
    $('#file_upload').uploadifive({
        'auto': false,
        'dnd': true,
        'checkScript': 'check-exists.php',
        'onUpload' : function(){
                $('#file_upload').data('uploadifive').settings.formData = {
                        'timestamp': '<?php echo $timestamp;?>',
                        'token': '<?php echo md5('unique_salt' . $timestamp);?>',
                        'MyNumber': $('#MyInputVariable').val(),
                            }},
        'queueID': 'queue',
        'uploadScript': 'upload.php',
        'onUploadComplete': function(file, data) {console.log(data);}
    });
});

1 Comment

Looks like a more correct jQuery example to me! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.