Lots of code improvements

Code no longer relies on regular expressions, which are wasteful in resources. Also, it is more readable, less redundant and more 'PHP-way'.

I intend to make multiple file upload, if you do not do it soon.