View Issue Details

IDProjectCategoryView StatusLast Update
0012509mantisbtcode cleanuppublic2014-12-08 00:33
Reporterbartik Assigned Todhx  
PrioritynormalSeveritytrivialReproducibilityalways
Status closedResolutionfixed 
Platformx86OSWindowsOS VersionXP SP3
Product Version1.2.3 
Target Version1.3.0-beta.1Fixed in Version1.3.0-beta.1 
Summary0012509: 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/

TagsNo 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

0001-pathinfo.patch (1,372 bytes)   
attachment_test.PNG (59,845 bytes)   
attachment_test.PNG (59,845 bytes)   
pathinfo_utf8.zip (528 bytes)
attachment_test_1.PNG (64,163 bytes)   
attachment_test_1.PNG (64,163 bytes)   

Relationships

related to 0010611 closeddhx Attach not recognize correctly 
related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 

Activities

atrol

atrol

2010-11-03 18:17

developer   ~0027240

Could you please check if this works also for UTF-8 file names
Have also a look at 0010611 for this

bartik

bartik

2010-11-04 16:21

reporter   ~0027257

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.

dhx

dhx

2010-11-06 09:00

reporter   ~0027270

@bartik: thanks for testing. Are you able to perform another test using an extension that is UTF8 encoded, example: аттача.аттача

bartik

bartik

2010-11-06 15:38

reporter   ~0027272

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

dhx

dhx

2011-02-27 00:20

reporter   ~0028311

Thanks for the patch. I have removed the function entirely in favour of using the native PHP pathinfo() function - tested OK with UTF8.

grangeway

grangeway

2013-04-05 17:57

reporter   ~0036466

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master 0faec070

2011-02-27 00:15

dhx


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