Fixed code for gallery uploads