使用 Ajax 上传上传压缩文件夹
在我的网站中,我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据此代码,您应该将 .zip 扩展名添加到允许列表中。
现在它还应该上传 zip 文件。
希望这个答案对您有任何帮助。
According to this code you should add .zip extension to your allow list.
Now it should also upload zip files.
Hope this answer helps you in any way.
该代码在 onSubmit 选项的函数中检查文件扩展名。
由于您只允许图像扩展名,因此 zip 文件会因为不是图像而被拒绝。
您需要向 if 子句添加扩展,如下所示:
还有其他类型的压缩格式,不要忘记添加您能够支持的这些格式。
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:
There are other types of zipped formats, don't forget to add these you're able to support.