Media: Improve handling of extensionless filenames.
Merge of [37756] to the 3.9 branch. See #37111. Built from https://develop.svn.wordpress.org/branches/3.9@37822 git-svn-id: http://core.svn.wordpress.org/branches/3.9@37787 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9858249ed9
commit
b7be0d01c0
|
@ -1024,7 +1024,8 @@ function remove_accents($string) {
|
||||||
* operating systems and special characters requiring special escaping
|
* operating systems and special characters requiring special escaping
|
||||||
* to manipulate at the command line. Replaces spaces and consecutive
|
* to manipulate at the command line. Replaces spaces and consecutive
|
||||||
* dashes with a single dash. Trims period, dash and underscore from beginning
|
* dashes with a single dash. Trims period, dash and underscore from beginning
|
||||||
* and end of filename.
|
* and end of filename. It is not guaranteed that this function will return a
|
||||||
|
* filename that is allowed to be uploaded.
|
||||||
*
|
*
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*
|
*
|
||||||
|
@ -1048,6 +1049,14 @@ function sanitize_file_name( $filename ) {
|
||||||
$filename = preg_replace('/[\s-]+/', '-', $filename);
|
$filename = preg_replace('/[\s-]+/', '-', $filename);
|
||||||
$filename = trim($filename, '.-_');
|
$filename = trim($filename, '.-_');
|
||||||
|
|
||||||
|
if ( false === strpos( $filename, '.' ) ) {
|
||||||
|
$mime_types = wp_get_mime_types();
|
||||||
|
$filetype = wp_check_filetype( 'test.' . $filename, $mime_types );
|
||||||
|
if ( $filetype['ext'] === $filename ) {
|
||||||
|
$filename = 'unnamed-file.' . $filetype['ext'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Split the filename into a base and extension[s]
|
// Split the filename into a base and extension[s]
|
||||||
$parts = explode('.', $filename);
|
$parts = explode('.', $filename);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue