如何使用文件上传jQuery

如何使用文件上传jQuery

问题描述:

当文件不是图像类型时立即显示错误消息我正在使用jQuery File Upload Plugin 5.21将文件上传到我的网站。我的需要是在添加不像图像的文件类型时通过检查文件扩展名立即显示错误消息。如何使用内置函数来检查此操作,如_onSend_beforeSend但不知道使用它。 (如果可能,可以显示演示?)。Thankx提前如何使用文件上传jQuery

+0

你想要这样的代码吗? – 2014-09-30 07:16:16

+0

@geek如果他们是任何例子。它会更有帮助。谢谢 – 2014-09-30 08:25:21

我用这个代码,并制作了我的操作结果

$('#yourfileuploader').fileupload().bind('fileuploadadded', function (e, data) { 
         var fileType = data.files[0].name.split('.').pop(), allowdtypes = 'jpeg,jpg,png,gif'; 
         if (allowdtypes.indexOf(fileType) < 0) { 
          alert('Invalid file type, aborted'); 
          return false; 
         } 
        }); 

我从 blueImp/jquery file upload - How do I get the error message if the file type was not accepted?

得到它谢谢

您可以使用下面的代码。

  • 的JavaScript

add: function (e, data) { var goUpload = true; var uploadFile = data.files[0]; if (!(/\.(gif|jpg|jpeg|tiff|png)$/i).test(uploadFile.name)) { common.notifyError('You must select an image file or your message.......'); goUpload = false; }if (goUpload == true) { data.submit(); } },

+0

我正在尝试使用_onAdd。我会检查这一点。谢谢你的回答 – 2014-09-30 08:28:12