sanitize_filename_before_upload

Sanitize media file name before uploading.

Description

(string) sanitize_filename_before_upload( (string) $filename ); 

Returns (string)

Parameters (1)

0. $filename (string)
The filename.

Usage

  1. if ( !function_exists( 'sanitize_filename_before_upload' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'rtmedia-for-wordpress-buddypress-and-bbpress/app/main/controllers/template/rtmedia-actions.php'; 
  3.  
  4. // The filename. 
  5. $filename = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = sanitize_filename_before_upload($filename); 
  9.  

Defined (1)

The function is defined in the following location(s).

/app/main/controllers/template/rtmedia-actions.php  
  1. function sanitize_filename_before_upload( $filename ) { 
  2.  
  3. $info = pathinfo( $filename ); 
  4. $ext = empty( $info['extension'] ) ? '' : '.' . $info['extension']; 
  5. $name = basename( $filename, $ext ); 
  6. $final_file_name = $name; 
  7. $special_chars = array( '?', '[', ']', '/', '\\', '=', '<', '>', ':', ';', ', ', "'", '"', '&', '$', '#', '*', '(', ')', '|', '~', '`', '!', '{', '}', chr( 0 ) ); 
  8. $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $final_file_name ); 
  9. $string = str_replace( $special_chars, '-', $final_file_name ); 
  10. $string = preg_replace( '/\+/', '', $string ); 
  11.  
  12. return remove_accents( $string ) . $ext; 
  13.