Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function gussExtension return wrong result, return csv instead of right answer "txt" or "text" #2066

Closed
lanxiuying opened this issue Jun 21, 2019 · 1 comment

Comments

@lanxiuying
Copy link

lanxiuying commented Jun 21, 2019

Direction
function gussExtension return wrong result, return csv instead of right answer "txt" or "text";

Describe the bug
when txt,text files uploaded

   if ($filelist = $this->request->getFiles()) {
                   var_dump($file->guessExtension());//return csv instead text
       }

**why this happend** **because $mime['csv'] include 'text/plain' in file "application\Config\Mimes.php",so function always return csv when the input is ‘text/plain’**

public static function guessExtensionFromType(string $type = ‘text/plain’){  
		$type = trim(strtolower($type), '. ');  
		foreach (self::$mimes as $ext => $types)  
		{  
			if (is_string($types) && $types == $type)  
			{  
				return $ext;  
			}  
			else if (is_array($types) && in_array($type, $types))  
			{  
				return $ext;  
			}  
		}  
		return null;  
	}`  

CodeIgniter 4 version
CodeIgniter 4 Development

Affected module(s)
system\Files
system\Files\File.php
application\Config\Mimes.php
Expected behavior, and steps to reproduce if appropriate
return file's correct mimetype
Context

  • OS: [e.g. Windows 7]
  • Web server [e.g. Apache 2.4]
  • PHP version [7.1] with module php_fileinfo active
@MGatner
Copy link
Member

MGatner commented Jun 22, 2019

MIMES is in app/ intentionally (I presume) to encourage user updates, so feel free to edit it. MIMES are checked in the order they are listed in that config so if you want .txt to return text/plain you can move it higher. Since guessExtensionFromType is explicitly just matching off extension there is no way to differentiate between CSV and TXT, short of removing text/plain from the CSV list (which would be fine to do as well, if you prefer).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants