0

I have an input to load files and JavaScript code to get the file name, that I found here on Stack Overflow:

My input:

<%= file_field_tag 'file' %>

The JavaScript code:

var fullPath = document.getElementById('file').value;
if (fullPath) {
   var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
   var filename = fullPath.substring(startIndex);
   if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0) {
      filename = filename.substring(1);
   }
   alert(filename);
}

Instead of turn it into an alert(filename), is there a way to make it save the file name into a text file?

0 Answers0