Jump to content

Recommended Posts

2 Problems

 

Hi,

 

1 ) 

has anyone ever used the plupload ?, my problem right now is, when i triy uploading .gif files with big dimensions, it doesn't get through.

but with jpeg,jpg it does work

 

here's the current configuration of my plupload

                    'options' => array(
'runtimes' => 'gears,html5,flash,silverlight,browserplus',
                        'url' => $this->createUrl('upload'),
                        "max_file_size" => '10mb',
                        'chunk_size' => '1mb',
                        'unique_names' => true,
                        'resize' => array('width' => 900, 'height' => 900, 'quality' => 90),
                        'filters' => array(
                            array("title" => "Image files", "extensions" => "jpg,gif,png,jpeg")
                        ),

2) how to throw an error to the user that the upload has failed ? , like e.g while uploading the internet connection has failed.

and I wanna tell them that they need to re-upload the file?

 

I added this in the array

 

 

'Error' => 'js:function(up,file){
alert("File was not uploaded properly");
}',
Edited by sasori

Hey sasori,
 
just create a custom function and bind the plupload "FileUploaded" method to it. Check if all files are successfully uploaded on the server and the status of this connection is equal to 200.

Then pass this custom function to preinit.

So, it would like something like:

// added redirect function after uploading was successfully
function attachCallbacks(uploader) {
uploader.bind('FileUploaded', function(Up, File, Response) {
    // count total of uploaded files
    var u_count = uploader.total.uploaded;
    // get the length of uploaded files
    var f_length = uploader.files.length;
    // check the status and status of failed uploaded files
     if(!uploader.total.failed && Response.status == 200) {
      // redirect the page after successfully uploading images
        if((u_count+1) == f_length) window.location.assign('http://www......');
     } else {
     alert('Failed uploading'); return false;
       }
    })
}

All script:

<script type="text/javascript">
      // Convert divs to queue widgets when the DOM is ready
$(function() {
    $("#uploader").pluploadQueue({
        // General settings
        runtimes : 'gears,html5,flash',
        url : 'index.php?action=upload',
        max_file_size : '1mb',
        chunk_size : '1mb',
        unique_names : false,
        // redirect mod
        preinit : attachCallbacks,
        
        // Specify what files to browse for
        filters : [
            {title : "Allowed files", extensions : "jpg,gif,png,txt,doc,docx,pdf,zip"}
        ],

        // Flash settings
        flash_swf_url : 'js/plupload.flash.swf'

    });

    // Client side form validation
    $('form').submit(function(e) {
        var uploader = $('#uploader').pluploadQueue();

        // Files in queue upload them first
        if (uploader.files.length > 0) {
            // When all files are uploaded submit form
            uploader.bind('StateChanged', function() {
                if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                    $('form')[0].submit();
                }
            });  
            uploader.start();
        } else {
            alert('You must queue at least one file.');
        }

        return false;
    });
});

// added redirect function after uploaded
function attachCallbacks(uploader) {
uploader.bind('FileUploaded', function(Up, File, Response) {
    // count total of uploaded files
    var u_count = uploader.total.uploaded;
    // get the length of uploaded files
    var f_length = uploader.files.length;
    // check the status and status of failed uploaded files
     if(!uploader.total.failed && Response.status == 200) {
      // redirect the page after successfully uploading images
        if((u_count+1) == f_length)  window.location.assign('index.php');
     } else {
     alert('Failed uploading'); return false;
       }
    })
}

</script>

with regards to the issue, there's another thing, even if the response is "200" , if you check in firebug...you will see that there's 

"pink" colored bar in the timeline., does that mean incomplete upload? ..because the typical color of the "200" ok response is blue in firebug , right?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.