fixed file type issues

The code was checking the image's type using a simple method of checking its extension. it causes issue with dynamic files (like those generated by facebook) and overall is an incorrect way of doing it. i modified it so it will be based on the file's mime_type instead of the file's extension.
Joe Hoyle @joehoyle