Fix: Correctly find the next available voicemail greeting id (#7678)

when uploading to avoid using the same name as another greeting.
This commit is contained in:
Alex
2025-12-23 14:22:59 -07:00
committed by GitHub
parent 9f60bc2971
commit f3540a2546

View File

@@ -174,11 +174,32 @@
$file_ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); $file_ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$file_name = $_FILES['file']['name']; $file_name = $_FILES['file']['name'];
//check file extension //define the allowed file extensions
if ($file_ext == 'wav' || $file_ext == 'mp3' || $file_ext == 'ogg') { $allowed_extensions = ['wav', 'mp3', 'ogg'];
//get the next greeting id starting at 1 //check file extension
$greeting_id = count(glob($greeting_dir . '/greeting_*.*')) + 1; if (in_array($file_ext, $allowed_extensions)) {
//find the next available greeting id starting at 1
$greeting_id = 1;
while (true) {
$found_existing_file = false;
//check for wav, mp3, and ogg files with the current greeting id
foreach ($allowed_extensions as $extension) {
$potential_file_name = "greeting_{$greeting_id}.{$extension}";
if (file_exists($greeting_dir . '/' . $potential_file_name)) {
$found_existing_file = true;
break;
}
}
if (!$found_existing_file) {
break;
}
$greeting_id++;
}
//set the greeting file name //set the greeting file name
$greeting_file_name = "greeting_{$greeting_id}.{$file_ext}"; $greeting_file_name = "greeting_{$greeting_id}.{$file_ext}";