public static function createUniqueFilename($prefix, $extension = '', $randomChars = 32, $onlyReturnRandomizedPart = false, $charList = null) { do { $random = StringTools::random($randomChars, $charList); $file = $prefix . $random . $extension; $exists = file_exists($file); } while ($exists); if ($onlyReturnRandomizedPart) { return $random; } return $file; }