From 24920ecc7ca3b1fabd2b62f810f5f4b4a1d911bf Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Wed, 16 Jul 2025 11:03:04 -0600 Subject: [PATCH] fix speech creating empty files (#7426) --- app/recordings/recording_edit.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/recordings/recording_edit.php b/app/recordings/recording_edit.php index b1b377140d..966114883d 100644 --- a/app/recordings/recording_edit.php +++ b/app/recordings/recording_edit.php @@ -181,8 +181,11 @@ if (empty($_POST["persistformvar"])) { if (permission_exists('recording_edit')) { - //set the recording format - $recording_format = $recording_format ?? 'wav'; + //set the recording format for approved types + if (!in_array($recording_format, ['mp3', 'wav'], true)) { + //default to mp3 + $recording_format = 'mp3'; + } //build the setting object and get the recording path $recording_path = $settings->get('switch', 'recordings').'/'.$_SESSION['domain_name']; @@ -194,6 +197,17 @@ rename($recording_path.'/'.$recording_filename_original, $recording_path.'/'.$recording_filename); } + //create the file name + if (empty($recording_filename)) { + // Replace invalid characters with underscore + $recording_filename = preg_replace('#[^a-zA-Z0-9_\-]#', '_', $recording_name); + } + + //make sure the filename ends with the approved extension + if (!str_ends_with($recording_filename, ".$recording_format")) { + $recording_filename .= ".$recording_format"; + } + //determine whether to create the recording $create_recording = false; if ($speech_enabled && !empty($recording_voice) && !empty($recording_message)) {