Kichu
Kichu

Reputation: 3267

Uploading Zipped folder Using Ajax Upload

In my site I want to upload a zipped folder using ajax.

Code:

<script type="text/javascript">
    $(function(){
     var btnUpload=$('#file_mod');
        new AjaxUpload(btnUpload, {
            action: "index.php",
            name: 'file',
            onSubmit: function(file, ext){
            //alert(file);
                if (! (ext && /^(jpg|png|jpeg|gif|JPG|PNG|JPEG|GIF)$/.test(ext))){
                    // extension is not allowed 
                    return false;
                }           
            },
            onComplete: function(file, response){
            alert("success");
            }
     });
 </script>

But I don't know how ajax is used for zipped file uploading.

What should I change in my code?

Upvotes: 0

Views: 1555

Answers (2)

PvB
PvB

Reputation: 508

The code checks the file extension in the function for the onSubmit option. As you only allow image extensions the zip file is rejected as not being an image.

You need to add the extensions to the if clause like that:

if (! (ext && /^(jpg|png|jpeg|gif|JPG|PNG|JPEG|GIF|ZIP|zip)$/.test(ext))){
    // extension is not allowed 
    return false;
}           

There are other types of zipped formats, don't forget to add these you're able to support.

Upvotes: 0

rasmusx
rasmusx

Reputation: 905

According to this code you should add .zip extension to your allow list.

if (! (ext && /^(zip|ZIP)$/.test(ext))){
    // extension is not allowed 
    return false;
}

Now it should also upload zip files.

Hope this answer helps you in any way.

Upvotes: 1

Related Questions