使用 Ajax 上传上传压缩文件夹

发布于 2024-12-27 10:08:35 字数 718 浏览 0 评论 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是如何用于压缩文件上传的。

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稚然 2025-01-03 10:08:35

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

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

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

希望这个答案对您有任何帮助。

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.

剪不断理还乱 2025-01-03 10:08:35

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

您需要向 if 子句添加扩展,如下所示:

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文