WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/sanitize file name

Description

Sanitizes a filename replacing whitespace with dashes

Removes special characters that are illegal in filenames on certain operating systems and special characters requiring special escaping to manipulate at the command line. Replaces spaces and consecutive dashes with a single dash. Trim period, dash and underscore from beginning and end of filename.

The special characters are passed through the sanitize_file_name_chars filter before removing them from the file name, allowing plugins to change which characters are considered invalid. After sanitize_file_name() has done its work, it passes the sanitized file name through the sanitize_file_name filter.

Usage

<?php sanitize_file_name$name ?>

Parameters

$name
(string) (required) The file name
Default: None

Return Values

(string) 
Sanitized file name

Examples

Notes

Change Log

Since: 2.1

Source File

sanitize_file_name() is located in wp-includes/formatting.php

Related

Functions

sanitize_file_name() is in a class of functions that help you sanitize potentially unsafe data which allow you to pass an arbitrary variable and receive the clean version based on data type. Others include:

Filters

See also index of Function Reference and index of Template Tags.