$uploaddir = preg_replace("/\\//", "\\", $uploaddir);
 }
 if (!file_exists($uploaddir)) {
     mkdir($uploaddir, 0777, true);
 }
 //        error_log( print_R($file,TRUE) );
 //        error_log($target_file_name);
 //        error_log($file_reference);
 //        error_log($uploaddir);
 if (!move_uploaded_file($file['tmp_name'], $uploaddir . $target_file_name)) {
     $results['note'] = util_lang('msg_file_upload_failed_copy_from_temp');
     echo json_encode($results);
     exit;
 }
 // get all the specimen images for the given specimen
 $otherImages = Specimen_Image::getAllFromDb(['specimen_id' => $specimenId], $DB);
 // figure out the lowest ordering value - the ordering for the new image will be that - 1
 $new_spec_ordering = 0;
 foreach ($otherImages as $otherImage) {
     if ($otherImage->ordering <= $new_spec_ordering) {
         $new_spec_ordering = $otherImage->ordering - 1;
     }
 }
 // create a new specimen image object, linked to that specimen and with the approp ordering and file info
 $newSpecimenImage = Specimen_Image::createNewSpecimenImageForSpecimen($specimenId, $DB);
 $newSpecimenImage->ordering = $new_spec_ordering;
 $newSpecimenImage->image_reference = $file_reference;
 // save the new specimen image object (end w/ approp error & note on failure)
 $newSpecimenImage->updateDb();
 if (!$newSpecimenImage->matchesDb) {
     $results['note'] = util_lang('msg_database_update_failed');
 public function loadImages()
 {
     $this->images = Specimen_Image::getAllFromDb(['specimen_id' => $this->specimen_id, 'flag_delete' => FALSE], $this->dbConnection);
     usort($this->images, 'Specimen_Image::cmp');
 }