Allow to resolve known mime type to file extension
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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