mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 02:44:53 +00:00
Updated All Exports to include your company name if exporting all and if exporting just from a client prepend the client name to file, introduced a sanitize_filename function and used it for the exports to always get a clean file name that works on every OS
This commit is contained in:
@@ -1694,4 +1694,34 @@ function redirect($url = null, $permanent = false) {
|
||||
function flash_alert(string $message, string $type = 'success'): void {
|
||||
$_SESSION['alert_type'] = $type;
|
||||
$_SESSION['alert_message'] = $message;
|
||||
}
|
||||
|
||||
// Sanitize File Names
|
||||
function sanitize_filename($filename, $strict = false) {
|
||||
// Remove path information and dots around the filename
|
||||
$filename = basename($filename);
|
||||
|
||||
// Replace spaces and underscores with dashes
|
||||
$filename = str_replace([' ', '_'], '-', $filename);
|
||||
|
||||
// Remove anything which isn't a word, number, dot, or dash
|
||||
$filename = preg_replace('/[^A-Za-z0-9\.\-]/', '', $filename);
|
||||
|
||||
// Optionally make filename strict alphanumeric (keep dot and dash)
|
||||
if ($strict) {
|
||||
$filename = preg_replace('/[^A-Za-z0-9\.\-]/', '', $filename);
|
||||
}
|
||||
|
||||
// Avoid multiple consecutive dashes
|
||||
$filename = preg_replace('/-+/', '-', $filename);
|
||||
|
||||
// Remove leading/trailing dots and dashes
|
||||
$filename = trim($filename, '.-');
|
||||
|
||||
// Ensure it’s not empty
|
||||
if (empty($filename)) {
|
||||
$filename = 'file';
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
Reference in New Issue
Block a user