WIP: Copy file_save_upload() to get better error details

I know this is an adaptation from core, but this function is way too long and does too many things. I am OK leaving it like this for comparison reasons with `file_save_upload`.