Skip to content

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

Description

@lanxiuying

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions