• Resolved iSpectra

    (@ispectra)


    ?????♂? Greetings,

    is it possible to retain spaces in files uploaded instead of them being substituted with minuses (-) after uploading?

    Original and expected filename to see in the media library: “a filename for a picture.png”
    Actual filename: “a-filename-for-a-picture.png”

    I really do appreciate the time you’re taking to answer my question. ????

    Best Regards
    Jonathan

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @ispectra

    I hope you’re well today!

    Spaces from filenames are removed not by Forminator but by WordPress itself. Since 2.0 there’s a “sanitize_file_name()” function used to remove some special characters and replaces spaces with dashes.

    It’s done in order to improve security but mostly compatibility with filesystems that do not support (or “handle well”) spaces in file names.

    You can override this with simple additional code like this:

    <?php 
    
    function my_unsanitize_file_name( $filename, $filename_raw ) {
    	
    	return $filename_raw;
    	
    }
    
    add_filter( 'sanitize_file_name', 'my_unsanitize_file_name', 10, 2);

    You can add it as Must Use plugin:

    – create an empty file with a .php extension (e.g. “no-filename-sanitization.php”)
    – copy and paste above code into it
    – save the file and upload it to “/wp-content/mu-plugins” folder of your site’s WordPress installation; if there’s no “mu-plugins” folder directly in “wp-content”, just create an empty one first.

    Best regards,
    Adam

    Thread Starter iSpectra

    (@ispectra)

    Greetings Adam,

    this worked perfectly for me. Thank you so much for your swift and professional response. Is there a way to buy you a coffee as a way to say thanks?

    Best regards,
    Jonathan

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @ispectra

    I’m glad to know it’s working for you now!

    No need to buying me coffee, the best “thanks” for me is just to know I could help. It makes me happy ?? But I appreciate the offer a lot ??

    I’ll mark this ticket as resolved but feel free to re-open it if needed.

    Have a great day,
    Adam

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Retain spaces in files uploaded’ is closed to new replies.