WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/04/2009 08:20:48 PM (13 years ago)
Author:
ryan
Message:

sanitize_file_name() improvements. Props sivel. fixes #9416

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r11170 r11178  
    20142014 */
    20152015function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
    2016     $filename = strtolower( $filename );
     2016    // sanitize the file name before we begin processing
     2017    $filename = sanitize_file_name($filename);
     2018
    20172019    // separate the filename into a name and extension
    20182020    $info = pathinfo($filename);
    20192021    $ext = !empty($info['extension']) ? $info['extension'] : '';
    20202022    $name = basename($filename, ".{$ext}");
    2021 
     2023   
    20222024    // edge case: if file is named '.ext', treat as an empty name
    20232025    if( $name === ".$ext" )
     
    20312033
    20322034        if ( !empty( $ext ) )
    2033             $ext = strtolower( ".$ext" );
    2034 
    2035         $filename = str_replace( $ext, '', $filename );
    2036         // Strip % so the server doesn't try to decode entities.
    2037         $filename = str_replace('%', '', sanitize_title_with_dashes( $filename ) ) . $ext;
     2035            $ext = ".$ext";
    20382036
    20392037        while ( file_exists( $dir . "/$filename" ) ) {
Note: See TracChangeset for help on using the changeset viewer.