views:

71

answers:

4

Hi,

I am using Jquery Uploadify for images upload with PHP, here i have multiple instances of uploadify and and each instance is uploading images in different folders.

I want to second instance of uplaodify will start uploading images only after first instance of uploadify uploaded selected image.

$('#listing_image').uploadifySettings('folder','listing_image_TempImage'); $('#listing_image').uploadifyUpload(); $('#listing_image1').uploadifySettings('folder','listing_image1_TempImage'); $('#listing_image1').uploadifyUpload();

i.e 'listing_image1' will get call when processing of 'listing_image' will be completed. How i can achieve this behavior ??

+2  A: 

You can create a "callback" function, that fires when the first upload is completed.

$('#listing_image').uploadify({
 'folder'    : '/listing_image_TempImage',
 onComplete: function(){ 
  $('#listing_image1').uploadify({
   'folder'    : '/listing_image_TempImage'
  });
 }
});

With 6 (one after the other) uploads:

$('#listing_image').uploadify({
    'folder'    : '/listing_image_TempImage',
    onComplete: function(){ 
        $('#listing_image1').uploadify({
            'folder'    : '/listing_image_TempImage1',
            onComplete: function(){ 
                $('#listing_image2').uploadify({
                    'folder'    : '/listing_image_TempImage2',
                    onComplete: function(){ 
                        $('#listing_image3').uploadify({
                            'folder'    : '/listing_image_TempImage3',
                            onComplete: function(){ 
                                $('#listing_image4').uploadify({
                                    'folder'    : '/listing_image_TempImage4',
                                    onComplete: function(){ 
                                        $('#listing_image5').uploadify({
                                            'folder'    : '/listing_image_TempImage5'   
                                        });
                                    }   
                                });
                            }           
                        });
                    }
                });
            }
        });
    }
});

I assume that it's this uploadify you are talking about.

For at full list of available callbacks, look in the docs.

Webbies
Thanks for answer.yes, i am talking about same uplaodify...here i have 6 instances of uploadify so how i can implement "callback" for all 6 instances??? you example will work for only 2 instances.
Shatru
You are talking about having them all one after the other. So the fifth will only run after the fourth is complete?
Webbies
yes exactly , so how i can achieve this?
Shatru
and it might be user selected only 2nd, 4rd and 5th instances of uploadify so how we can handle this behavior ?
Shatru
i just added with 6, on after the other uploads. but if the user can select which uploads he want, that's a bit more tricky. You need some variables. I'll make a proff of concept, that you can modify, and post a new answer when i got it.
Webbies
Thank you very much Webbies but here i got one problem.... i checked for first two instances but this code is not uplaoding images for first 2 instances... $('#listing_image').uploadify({ 'folder' : '/listing_image_TempImage', onComplete: function(){ $('#listing_image1').uploadify({ 'folder' : '/listing_image_TempImage' }); }});
Shatru
A: 

If you use sessions, script execution is going to be delayed on server side so each upload will get processed one after another anyway.

Pekka
Hi Pekka, actually now requirement is changed...Now we have 6 instances of Uploadify and each instance will have fixed folder where images will upload so here i want second instance of uplaodify will call only when processing first instance of uploadify completed. Given code is not uplaoding images $('#listing_image').uploadify({ 'folder' : '/listing_image_TempImage', onComplete: function(){ $('#listing_image1').uploadify({ 'folder' : '/listing_image_TempImage' }); }});
Shatru
A: 

Thankyou Webbies... but now file uploading is not working... i think : $('#listing_image').uploadify({ " is not uploading images.

Shatru
A: 

I cant add a comment to you'r answer yet. So i'm writing it here instead.

Try to make one upload work by using this (make sure the links point's to the correct locations):

$('#listing_image').uploadify({
    'uploader'  : 'uploadify.swf',
    'script'    : 'uploadify.php',
    'cancelImg' : 'cancel.png',
    'folder'    : '/listing_image_TempImage',
    onComplete: function(){ 
        // Do oncomplete stuff. 
    }
});

When you can get that to work, then you should be able to make this work.

var uploads = [2,4,5]; // Only number 2,4 and 5
var numberofuploads = uploads.length; // How many is that?
var folderlist = [0, '/folder1', '/folder2', '/folder3', '/folder4', '/folder5', '/folder6']; // List of folders to upload to
var listingimageslist = [0, '#listing_image1', '#listing_image2', '#listing_image3', '#listing_image4', '#listing_image5', '#listing_image6']; // List of form selectors. 

var folder = folderlist[uploads[0]]; // What folder should this form upload to
var listingimages = listingimageslist[uploads[0]]; // With what selector can the form be found?
if (numberofuploads > 1)
{
    var next = 1; // What upload to initiate after this one?
}
initUpload(listingimages,folder); // make the upload thing work. 


function initUpload(e,folder)
{
    $(e).uploadify({
        'folder'    : folder,
        'uploader'  : 'uploadify.swf',
        'script'    : 'uploadify.php',
        'cancelImg' : 'cancel.png',
        onComplete: function(){ 
            var folder = folderlist[uploads[next]];
            var listingimages = listingimageslist[uploads[next]];
            next++
            if (numberofuploads != next)
            {
                initUpload(listingimages,folder);
            }
        }
    });
};

I didn't test the code, but you should be able to make it work if you know a bit of javascript.

Remenber to have all your jQuery code in a $(document).ready like this:

$(document).ready(function() {
 // Insert code here
});
Webbies
Thank you very much Webbies but here i got one problem.... i checked for first two instances but this code is not uplaoding images for first 2 instances... $('#listing_image').uploadify({ 'folder' : '/listing_image_TempImage', onComplete: function(){ $('#listing_image1').uploadify({ 'folder' : '/listing_image_TempImage' }); } });
Shatru
Try to make just one work, using the first snippet of code i provided in this answer.
Webbies