Skip to content

Commit

Permalink
Issue #12509: Replace file_get_extension with PHP native pathinfo
Browse files Browse the repository at this point in the history
The file_get_extension function within file_api is unnecessary as PHP's
native pathinfo function performs the same role. Tested with UTF8
filenames on PHP 5.3.5 and it can split paths/filenames into their
correct components.
  • Loading branch information
davidhicks committed Feb 27, 2011
1 parent 5b0fdc5 commit 0faec07
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions core/file_api.php
Expand Up @@ -158,7 +158,7 @@ function file_can_delete_bug_attachments( $p_bug_id, $p_uploader_user_id = null
function file_get_icon_url( $p_display_filename ) {
$t_file_type_icons = config_get( 'file_type_icons' );

$ext = utf8_strtolower( file_get_extension( $p_display_filename ) );
$ext = utf8_strtolower( pathinfo( $p_display_filename, PATHINFO_EXTENSION ) );
if( is_blank( $ext ) || !isset( $t_file_type_icons[$ext] ) ) {
$ext = '?';
}
Expand Down Expand Up @@ -313,7 +313,7 @@ function file_get_visible_attachments( $p_bug_id ) {
$t_attachment['preview'] = false;
$t_attachment['type'] = '';

$t_ext = strtolower( file_get_extension( $t_attachment['display_name'] ) );
$t_ext = strtolower( pathinfo( $t_attachment['display_name'], PATHINFO_EXTENSION ) );
$t_attachment['alt'] = $t_ext;

if ( $t_attachment['exists'] && $t_attachment['can_download'] && $t_filesize != 0 && $t_filesize <= config_get( 'preview_attachments_inline_max_size' ) ) {
Expand Down Expand Up @@ -531,7 +531,7 @@ function file_type_check( $p_file_name ) {
$t_disallowed_files = config_get( 'disallowed_files' );;

# grab extension
$t_extension = file_get_extension( $p_file_name );
$t_extension = pathinfo( $p_file_name, PATHINFO_EXTENSION );

# check against disallowed files
$t_disallowed_arr = explode( ',', $t_disallowed_files );
Expand Down Expand Up @@ -849,28 +849,6 @@ function file_ensure_uploaded( $p_file ) {
}
}

# Get extension given the filename or its full path.
function file_get_extension( $p_filename ) {
$t_extension = '';
$t_basename = $p_filename;
if( utf8_strpos( $t_basename, '/' ) !== false ) {
// Note that we can't use end(explode(...)) on a single line because
// end() expects a reference to a variable and thus we first need to
// copy the result of explode() into a variable that end() can modify.
$t_components = explode( '/', $t_basename );
$t_basename = end( $t_components );
}
if( utf8_strpos( $t_basename, '\\' ) !== false ) {
$t_components = explode( '\\', $t_basename );
$t_basename = end( $t_components );
}
if( utf8_strpos( $t_basename, '.' ) !== false ) {
$t_components = explode( '.', $t_basename );
$t_extension = end( $t_components );
}
return $t_extension;
}

/**
* Get file content
*
Expand Down

0 comments on commit 0faec07

Please sign in to comment.