php / php/php-src

Allow to resolve known mime type to file extension

Open
#12,918 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: fileinfo Feature Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

Mime type to file extension is already supported by FILEINFO_EXTENSION but it is impossible to specify the mime type :).

I expect code like:

$mimetype = 'application/zip';
$finfo = finfo_open(FILEINFO_EXTENSION);
var_dump(finfo_buffer($finfo, $mimetype, FILEINFO_EXTENSION)); // notice $mimetype is mime type not file data

to dump zip.

It should be possible to find the file magic data by iterating the magic data like in https://github.com/file/file/blob/FILE5_45/src/softmagic.c#L135, the mime/ext is defined in https://github.com/file/file/blob/FILE5_45/src/file.h#L371.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the finfo_open and finfo_buffer entry points and compare the requested behavior with file's softmagic.c and file.h references. Trace how FILEINFO_EXTENSION currently resolves data, then verify that a MIME-type input such as application/zip produces zip without changing existing behavior. Add or update focused tests for the new resolution path.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.