There is a physical path from the root:
/upload/user/2014/14/14/pid_113456/avatar/2132434242.jpg You need to get the output:
/img/113456/2132434242.jpg when taking into account that /2014/14/14/ - folders created by time, year, month, day. In other words, there are many of them.
The fact is that the project is very large (a startup), and a lot of perezalivat ... Hellish work. Needs have changed - and now it is necessary to shorten the path.