ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

"Safe File name" in CF v5?

adrian99 11 May, 2015
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.
GreyHead 12 May, 2015
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
adrian99 12 May, 2015
Many thanks for a very comprehensive answer.
Max_admin 12 May, 2015
Hi,

This setting is available in v5 and its hardcoded, you can't disable it!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com