Question

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?

Était-ce utile?

La solution

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.

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top