if ( $fname &&
preg_match( '/-(?:\d+x\d+|scaled|rotated)$/',
$fname ) ) { $number = 1;
// At this point the file name may not be unique. This is tested below and the $number is incremented.
$filename =
str_replace( "{
$fname}{
$ext}", "{
$fname}-{
$number}{
$ext}",
$filename );
} /*
* Get the mime type. Uploaded files were already checked with wp_check_filetype_and_ext()
* in _wp_handle_upload(). Using wp_check_filetype() would be sufficient here.
*/
$file_type =
wp_check_filetype( $filename );
$mime_type =
$file_type['type'
];
$is_image =
( !
empty( $mime_type ) &&
str_starts_with( $mime_type, 'image/'
) );
$upload_dir =
wp_get_upload_dir();
$lc_filename = null;
$lc_ext =
strtolower( $ext );
$_dir =
trailingslashit( $dir );
/*
* If the extension is uppercase add an alternate file name with lowercase extension.
* Both need to be tested for uniqueness as the extension will be changed to lowercase
* for better compatibility with different filesystems. Fixes an inconsistency in WP < 2.9
* where uppercase extensions were allowed but image sub-sizes were created with
* lowercase extensions.
*/