1

I have an issue with the drag and drop of an image onto the website where if the file name has a bracket like [ or ] then it causes a problem with the upload. How do I check to see if the file name has this and if it does then how do I remove it?

function process_drop(evt) {
    evt.stopPropagation(); 
    evt.preventDefault(); 
    var files = evt.dataTransfer.files; 

    //CHECK TO SEE IF FILE NAME HAS A BRACKET ?

    // run through each file individually.
    for (var i = 0, f; f = files[i]; i++) {

    } 
} 
Sampson
  • 265,109
  • 74
  • 539
  • 565
Jason
  • 2,687
  • 3
  • 29
  • 40

1 Answers1

1
string.indexOf("]") != -1

indexOf returns the position of the string in the other string. If not found, it will return -1.

from here JavaScript: string contains


For your other questions:

var files = evt.dataTransfer.files;
//number of files
var count = files.length;
//the first file's info
var first = files[0];
//the first file's name
var name = first.name;

I found a pretty good link for you: HTML5 Drag and drop file api tutorial

Community
  • 1
  • 1
Jean-Bernard Pellerin
  • 12,556
  • 10
  • 57
  • 79
  • the file name is within the evt.dataTransfer.files object so how do I access the file name to run this code on it? There could be many files that the evt.dataTransfer.files object contains. – Jason Apr 30 '12 at 21:01