code: public static function makeSafe($file)
    {
      $regex = [ 
        '#(\.){2,}#', 
        '#[^A-Za-z0-9\.\_\- ]#', '#^\.#',
      ];
      
      $file = rtrim($file, '.');
      $clean = preg_replace($regex, ' ', $file);
      $clean = preg_replace("/[ \_]/", '-', $clean);
      $clean = preg_replace("/[\-]+/", '-', $clean);
      return $clean;
    }
docs: Makes file name safe to use
  
  @param  string  $file  The name of the file [not full path]
  @return string  The sanitised string