Imported code from Javer to better handle saving of files for photos.