0

I need to upload DOC and XLS files to my application. I'm using multifile.js for uploading the file.

I need to prevent uploading files except DOC and XLS - how can i achieve that?

Zathrus Writer
  • 4,311
  • 5
  • 27
  • 50
Optimus
  • 2,200
  • 8
  • 37
  • 71
  • perhaps if you included a link to the plugin you're using, that would help... also, I wouldn't depend on client-side verification alone here, since anyone can rename an EXE file into XSL and send it anyway – Zathrus Writer Sep 13 '13 at 08:46
  • @ZathrusWriter The plugin I'm using in my project is http://multifile.frantatoman.cz/#header-overview – Optimus Sep 13 '13 at 09:07

1 Answers1

4

This script should be put as a validation before file is submitted. It should also work for filenames which already contains '.'(dot) eg.. myfile.ms.xls etc...

var splitLength = parseInt($('#file').val().split('.').length)
var extensionCaseInsensitive = $('#file').val().split('.')[splitLength-1]    

if (extensionCaseInsensitive.toUpperCase() == 'DOC' || extensionCaseInsensitive.toUpperCase() == 'XLS') {
    // allow upload
}

But remember one thing if a user is literally naming a png image as doc file then we cannot check the contents to validate or probably it will a much longer and complicated exercise.

AurA
  • 12,135
  • 7
  • 46
  • 63