In Chronoforms v4, the File Upload action had a field called "Safe File name" which we could set to Yes or No. This appears to have gone in v5. How can I cleanse a file name?
I notice that there is a new field called "File name code". Must we now provide our own cleansing code? If so, could someone give an example?
Many thanks.
I notice that there is a new field called "File name code". Must we now provide our own cleansing code? If so, could someone give an example?
Many thanks.
Hi adrian99,
I hadn't noticed that it wasn't there any more :-(
The old CFv4 version used this
My Upload Files [GH] action used this function:
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
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
Hi,
This setting is available in v5 and its hardcoded, you can't disable it!
Regards,
Max
This setting is available in v5 and its hardcoded, you can't disable it!
Regards,
Max
This topic is locked and no more replies can be posted.