View Issue Details

IDProjectCategoryView StatusLast Update
0012509mantisbtcode cleanuppublic2014-12-08 00:33
ReporterbartikAssigned 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.

Relationships

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

Activities

bartik

bartik

2010-11-03 17:19

reporter  

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)
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.

bartik

bartik

2010-11-04 16:22

reporter  

attachment_test.PNG (59,845 bytes)
attachment_test.PNG (59,845 bytes)
bartik

bartik

2010-11-04 16:22

reporter  

pathinfo_utf8.zip (528 bytes)
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:16

reporter  

attachment_test_1.PNG (64,163 bytes)
attachment_test_1.PNG (64,163 bytes)
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 05:15:30

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.
mod - core/file_api.php Diff File

Issue History

Date Modified Username Field Change
2010-11-03 17:19 bartik New Issue
2010-11-03 17:19 bartik File Added: 0001-pathinfo.patch
2010-11-03 18:17 atrol Note Added: 0027240
2010-11-03 18:17 atrol Status new => feedback
2010-11-04 08:52 dhx Relationship added related to 0010611
2010-11-04 16:21 bartik Note Added: 0027257
2010-11-04 16:21 bartik Status feedback => new
2010-11-04 16:22 bartik File Added: attachment_test.PNG
2010-11-04 16:22 bartik File Added: pathinfo_utf8.zip
2010-11-06 09:00 dhx Note Added: 0027270
2010-11-06 09:00 dhx Assigned To => dhx
2010-11-06 09:00 dhx Status new => feedback
2010-11-06 09:00 dhx Target Version => 1.3.0-beta.1
2010-11-06 15:16 bartik File Added: attachment_test_1.PNG
2010-11-06 15:38 bartik Note Added: 0027272
2010-11-06 15:38 bartik Status feedback => assigned
2011-02-27 00:19 dhx Changeset attached => MantisBT master 0faec070
2011-02-27 00:20 dhx Note Added: 0028311
2011-02-27 00:20 dhx Status assigned => resolved
2011-02-27 00:20 dhx Fixed in Version => 1.3.0-beta.1
2011-02-27 00:20 dhx Resolution open => fixed
2013-04-05 17:57 grangeway Status resolved => acknowledged
2013-04-05 17:57 grangeway Note Added: 0036466
2013-04-05 18:07 grangeway Relationship added related to 0015721
2013-04-06 03:44 dregad Status acknowledged => resolved
2013-04-06 07:20 grangeway Status resolved => acknowledged
2013-04-06 09:26 dregad Tag Attached: 2.0.x check
2013-04-06 09:26 dregad Status acknowledged => resolved
2014-09-23 18:05 grangeway Tag Detached: 2.0.x check
2014-12-08 00:33 vboctor Status resolved => closed