Skip to content

PHP mimetype "text/x-php" missing #51124

@valorin

Description

@valorin

Symfony version(s) affected

v6.3.0

Description

The mime type map included in \Symfony\Component\Mime\MimeTypes is missing text/x-php, which is associated with PHP files, which prevents the MimeTypes::getDefault()->getExtensions() method from returning the valid extension for these files.

How to reproduce

  1. Create a simple PHP file:
    $ cat phpinfo.php
    <?php
    phpinfo();
    
  2. Confirm the filesystem can identify the mimetype:
    $ file -b --mime -- phpinfo.php
    text/x-php; charset=us-ascii
    
  3. Detect the mime and try to retrieve the extension with Symfony:
    use \Symfony\Component\Mime\MimeTypes;
    
    $mime = MimeTypes::getDefault()->guessMimeType('phpinfo.php');
    echo "Mime => {$mime}".PHP_EOL; 
    
    $extensions = MimeTypes::getDefault()->getExtensions($mime);
    echo "Extensions => ".implode(', ', $extensions);
    
    Mime => text/x-php
    Extensions => 
    

Possible Solution

The mapping of text/x-php => .php should be added to allow for proper detection of these files.

Additional Context

The Resources/bin/update_mime_types.php file suggests this might be a problem upstream, or something that can be hardcoded within that script? I'm not familiar with the mechanics of the mime type mapping, so I thought it best to report the issue directly here and seek further instructions. Please let me know if I need to report the issue elsewhere.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions