I'll leave the code review to someone else but I thought that I would bring up a few points.
You should create thumbnails of the images as they are uploaded. This will keep the full size images from needing to be downloaded until the user decides what they want to view.
You allow progressive JPEGs (image/pjpeg) but not normal JPEGs (image/jpeg). Why?
And what happens if the user has javascript disabled?