How to upload files into nested folders

I would like to upload files into a nested file structure, is this possible?

So if I have form on my site with the file upload field, and a user uploads a file “application.pdf”, I would like it to be placed into a folder called applications, with another folder inside that with their user id as the name.

I.e. the file structure would look like:
applications/1/application.pdf
applications/2/application.pdf

and so on for all users.