0

在我的网站中,我想使用 ajax 上传一个压缩文件夹。

代码:

<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>

但我不知道 ajax 是如何用于压缩文件上传的。

我应该在我的代码中更改什么?

4

2 回答 2

1

根据此代码,您应该将 .zip 扩展名添加到您的允许列表中。

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

现在它还应该上传 zip 文件。

希望这个答案能以任何方式帮助你。

于 2012-01-18T11:24:36.947 回答
0

代码检查函数中的文件扩展名以获取 onSubmit 选项。由于您只允许图像扩展名,因此 zip 文件被拒绝为不是图像。

您需要像这样将扩展添加到 if 子句:

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

还有其他类型的压缩格式,不要忘记添加您能够支持的这些。

于 2012-01-18T11:24:39.630 回答