defer reading the file until we checked the upload result / turned accidental global detect_encoding function into an anonymous one

detect_encoding() doesn't seem to be used by anyone outside this controller. Check all plugins
known to me.