From da2ad154d846516edb602bc6202465844969cb8c Mon Sep 17 00:00:00 2001 From: sparkyx Date: Wed, 17 Dec 2025 18:43:33 +0100 Subject: [PATCH] code : improve sanitize_filename function --- include/lib/ac_common.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php index 6a68c149f..82d295005 100644 --- a/include/lib/ac_common.php +++ b/include/lib/ac_common.php @@ -1887,9 +1887,10 @@ function generate_random_password($car):string /** * @brief removed invalid character when computing a filename, the suffix is kept * @param $filename String filename to sanitize + * @param $with_date (bool) true add the date in the filename, false do not add it * @return string without offending char */ -function sanitize_filename($filename) +function sanitize_filename($filename,$with_date=true) { // save the suffix $pos_prefix=strrpos($filename, "."); @@ -1905,8 +1906,11 @@ function sanitize_filename($filename) $filename=str_replace(array('/', '*', '<', '>', ';', ',', '\\', '.', ':', '(', ')', ' ', '[', ']'), "-", $filename); $filename_no=substr($filename, 0, $pos_prefix); - - $new_filename=strtolower($filename_no)."-".date("Ymd-Hi").$filename_suff; + if ( $with_date) + $new_filename=strtolower($filename_no)."-".date("Ymd-Hi").$filename_suff; + else + $new_filename=strtolower($filename_no).$filename_suff; + return $new_filename; } /**