Hi adrian99,
I hadn't noticed that it wasn't there any more :-(
The old CFv4 version used this
$file_name = JFile::makeSafe($file_post['name']);
but this does not remove spaces as far as I can see. Here is the function:
/**
* Makes file name safe to use
*
* @param string $file The name of the file [not full path]
*
* @return string The sanitised string
*
* @since 11.1
*/
public static function makeSafe($file)
{
// Remove any trailing dots, as those aren't ever valid file names.
$file = rtrim($file, '.');
$regex = array('#(\.){2,}#', '#[^A-Za-z0-9\.\_\- ]#', '#^\.#');
return trim(preg_replace($regex, '', $file));
}
My Upload Files [GH] action used this function:
/**
* source: http://cubiq.org/the-perfect-php-clean-url-generator
* author: Matteo Spinelli
* MIT License / http://creativecommons.org/licenses/by-sa/3.0/ (please re-check at source)
*/
function toSlug($str, $replace=array(), $delimiter='-')
{
setlocale(LC_ALL, 'en_US.UTF8');
if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
return $clean;
}
, or there is a more comprehensive version on Google Code
here.
Whichever does the cleaning you need, you'd use a Custom Code action after the Upload Files action to create the new name, then 'move' the file to rename it; then update $form->files with the new information.
Bob