View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0012509 | mantisbt | code cleanup | public | 2010-11-03 17:19 | 2014-12-08 00:33 |
Reporter | bartik | Assigned To | dhx | ||
Priority | normal | Severity | trivial | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Platform | x86 | OS | Windows | OS Version | XP SP3 |
Product Version | 1.2.3 | ||||
Target Version | 1.3.0-beta.1 | Fixed in Version | 1.3.0-beta.1 | ||
Summary | 0012509: replacement for file_get_extension | ||||
Description | The original code of file_get_extension is replaced by pathinfo. The file_get_extension itself is only 3 times used in the file_api.php so probably no big deal. | ||||
Additional Information | http://cowburn.info/2008/01/13/get-file-extension-comparison/ | ||||
Tags | No tags attached. | ||||
Attached Files | 0001-pathinfo.patch (1,372 bytes)
From 7b9812d4f258a888629480e6388874a494006628 Mon Sep 17 00:00:00 2001 From: unknown <Peter@.(none)> Date: Wed, 3 Nov 2010 22:03:46 +0100 Subject: [PATCH] pathinfo --- core/file_api.php | 19 +------------------ 1 files changed, 1 insertions(+), 18 deletions(-) diff --git a/core/file_api.php b/core/file_api.php index 3c61769..b5b2e43 100644 --- a/core/file_api.php +++ b/core/file_api.php @@ -834,22 +834,5 @@ 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; + return pathinfo($p_filename, PATHINFO_EXTENSION); } -- 1.6.2.msysgit.0.186.gf7512 | ||||
Could you please check if this works also for UTF-8 file names |
|
The file Проверка аттача.png is uploaded fine with the pathinfo modification (I have dowloaded it from the issue 10611 if this is what you mean.) And I have run a simple test for path info if it helps. The source is in the attachment (of the test). It is UTF-8 encoded (what else). Seems working fine. Any other suggestions how to test it are welcome. |
|
@bartik: thanks for testing. Are you able to perform another test using an extension that is UTF8 encoded, example: аттача.аттача |
|
The file is uploaded. In the DB it is identified as application/octet-stream (the uploaded file) even when it is just the renamed image Проверка аттача.png |
|
Thanks for the patch. I have removed the function entirely in favour of using the native PHP pathinfo() function - tested OK with UTF8. |
|
Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch |
|
MantisBT: master 0faec070 2011-02-27 00:15 Details Diff |
Issue 0012509: Replace file_get_extension with PHP native pathinfo 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. |
Affected Issues 0012509 |
|
mod - core/file_api.php | Diff File |