[#2057] Fix filename munging

Issue #2057 

If we upload a file with a huge name then the extension gets eaten and we end up with the datastore not being able to import the file correctly if the format has not been set for the resource

Also it seems browsers on windows 7 seem to pass the whole path along with the file name so this creates problems for these users.

So we remove the path and try to keep the extension - really long extensions (over 20 chars) get truncated but these are probably erroneous extensions anyway.
I'm not sure it is ok to abbreviate "extension" in this function name.