validExtensions = $array; } public function setSizeLimit($bytes) { $this->sizeLimit = $bytes; } public function validate($filesArrayElement) { if (!$filesArrayElement['name']) { return self::MISSING; } if ($filesArrayElement['error'] !== UPLOAD_ERR_OK) { switch ($filesArrayElement['error']) { case UPLOAD_ERR_FORM_SIZE: case UPLOAD_ERR_INI_SIZE: return self::TOOBIG; case UPLOAD_ERR_NO_FILE: case UPLOAD_ERR_PARTIAL: return self::MISSING; case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_EXTENSION: default: // These throw an exception because it needs to be investigated by a developer throw new Exception('System error while uploading file.'); } } // Valid File Type? if ($this->validExtensions) { $extension = pathinfo($filesArrayElement['name'], PATHINFO_EXTENSION); if (!in_array(strtolower($extension), $this->validExtensions)) { return self::EXTENSIONINVALID; } } // Within Filesize Limit? if ($this->sizeLimit) { if (filesize($filesArrayElement['tmp_name']) > $this->sizeLimit) { return self::TOOBIG; } } return false; } }