Topic: Get upload filename after User selects file to upload?

Is there a way to get the filename after the User selects a file to upload, before post?

If I had to guess, I'd look for a client-side event on the file upload element which could be handled in JavaScript.

Last edited by ejstembler (2011-07-29 10:54:47)

Re: Get upload filename after User selects file to upload?

Yeah, you can use javascript for that. I usually use jQuery and formtastic, so for one of those projects the code would look something like

$(function() {
  $("form .file input").change(function() {
    var fileName = $(this).val();
    // do stuff with fileName
  });
}

If you aren't using formtastic, then you will just have to figure out what selectors to use in order to grab that input (but formtastic is awesome in my opinion, so...). If you aren't using jQuery (but jQuery is awesome in my opinion, so...) then again, you will have to modify this to work with whatever framework you are using (assuming you are using a framework).