views:

1205

answers:

2

Hello there,

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 "scriptData" method that allows me to send over key value pairs to the uploadify.php script. But the problem is that the scriptData method grabs its values upon page load(uploadify initialization). Thus when a user is on the page changing values, scriptData still only has the default values that were there on page load.

Is there anyway around this?

Thanks a million!

Possible solution: I was reading the manual further and discovered that you can change the settings through a function call. Possibly on the right track?

$('#fileInput').uploadifySettings('scriptData', getKeyValuePairs()).uploadifyUpload();

working on it now..

+1  A: 

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>
pixeline
Hey, thanks for taking your time to help!I've been trying your onOpen suggestion but it doesn't seems to want to update the default values.. I'll keep trying using this function, though. Seems like the way to do it..
@pixeline: OnSelect worked! But the only problem i see with this method is if the user changes the project after they're done choosing images. It won't update. May have to make a method outside of the uploadify function!
just register a click handler with you upload button that updates the settings for the input.`$('.upload').click(function(){ /* get form values and update uploadifySettings */});`
prodigitalson
A: 

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.

Donny Kurnia