code : improve sanitize_filename function
This commit is contained in:
parent
8462e4ffe3
commit
da2ad154d8
1 changed files with 7 additions and 3 deletions
|
|
@ -1887,9 +1887,10 @@ function generate_random_password($car):string
|
||||||
/**
|
/**
|
||||||
* @brief removed invalid character when computing a filename, the suffix is kept
|
* @brief removed invalid character when computing a filename, the suffix is kept
|
||||||
* @param $filename String filename to sanitize
|
* @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
|
* @return string without offending char
|
||||||
*/
|
*/
|
||||||
function sanitize_filename($filename)
|
function sanitize_filename($filename,$with_date=true)
|
||||||
{
|
{
|
||||||
// save the suffix
|
// save the suffix
|
||||||
$pos_prefix=strrpos($filename, ".");
|
$pos_prefix=strrpos($filename, ".");
|
||||||
|
|
@ -1905,8 +1906,11 @@ function sanitize_filename($filename)
|
||||||
$filename=str_replace(array('/', '*', '<', '>', ';', ',', '\\', '.', ':', '(', ')', ' ', '[', ']'), "-", $filename);
|
$filename=str_replace(array('/', '*', '<', '>', ';', ',', '\\', '.', ':', '(', ')', ' ', '[', ']'), "-", $filename);
|
||||||
|
|
||||||
$filename_no=substr($filename, 0, $pos_prefix);
|
$filename_no=substr($filename, 0, $pos_prefix);
|
||||||
|
if ( $with_date)
|
||||||
$new_filename=strtolower($filename_no)."-".date("Ymd-Hi").$filename_suff;
|
$new_filename=strtolower($filename_no)."-".date("Ymd-Hi").$filename_suff;
|
||||||
|
else
|
||||||
|
$new_filename=strtolower($filename_no).$filename_suff;
|
||||||
|
|
||||||
return $new_filename;
|
return $new_filename;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue