protected function get_new_id() { if (!file_exists("particle/")) { return 0; } $files = array(); $iterator = new FilesystemIterator("particle/", FilesystemIterator::SKIP_DOTS); while ($iterator->valid()) { array_push($files, $iterator->getFileName()); $iterator->next(); } if (sizeof($files) == 0) { return 0; } natsort($files); $lastFile = end($files); $name = explode(".", $lastFile); return intval($name[0]) + 1; }