$supported_types = array("image/png", "image/jpeg", "image/jpg", "image/gif"); if (!in_array($file["type"], $supported_types)) { $errMessage .= 'File type not supported. (' . $file["type"] . ')'; } } if (strlen($errMessage) > 0) { Service::returnError('Unable to upload files: ' . $errMessage); } // 2. Create thumbnail and resize image if it's too large for ($i = 0; $i < count($files); $i++) { $sourcefile = $files[$i]["tmp_name"]; $type = $files[$i]["type"]; $handler = new ImageHandler($sourcefile, $type); $files[$i]["thumb_file"] = $handler->getAppendedFileName($files[$i]["tmp_name"], "_thumb", true); $files[$i]["thumb_name"] = $handler->getAppendedFileName($files[$i]["name"], "_thumb", false); if ($handler->getWidth() > 800 || $handler->getHeight() > 800) { try { $destination = $files[$i]["tmp_name"]; $handler->resize(800, 800, $destination); } catch (Exception $ex) { Service::returnError('Unable to upload files. Error resizing file: ' . $ex->getMessage()); } } $files[$i]["width"] = $handler->getWidth(); $files[$i]["height"] = $handler->getHeight(); try { $destination = $files[$i]["thumb_file"]; $handler->resize(250, 250, $destination); } catch (Exception $ex) { Service::returnError('Unable to upload files. Error creating thumbnail: ' . $ex->getMessage()); }