Skip to content

[HttpFoundation] Mimetype invalid guesser, Suggest adding magic file?#6963

Closed
JoshuaEstes wants to merge 2 commits intosymfony:masterfrom
JoshuaEstes:FileinfoMagicFileMimeTypeGuesser
Closed

[HttpFoundation] Mimetype invalid guesser, Suggest adding magic file?#6963
JoshuaEstes wants to merge 2 commits intosymfony:masterfrom
JoshuaEstes:FileinfoMagicFileMimeTypeGuesser

Conversation

@JoshuaEstes
Copy link
Copy Markdown

So, I had an odd issue which has been discussed various times and already has a number of issues for it already. Not much has been really said in the ways of a good work around. Would like to see what the thoughts are on having a default magic file maintained. According to http://www.php.net/manual/en/function.finfo-open.php you are able to pass in your own. Which should clear up some of the "application/zip" for docx files and others.

Q A
Bug fix? n
New feature? y
BC breaks? n
Deprecations? n
Tests pass? y
Fixed tickets n/a
License MIT

@fabpot
Copy link
Copy Markdown
Member

fabpot commented Feb 4, 2013

Having our own magic file does not sound good but as this is something that come up from time to time, that might be a good idea after all. Can you reference all the other tickets here to get easy access to past discussions?

@JoshuaEstes
Copy link
Copy Markdown
Author

Issue #5258
Issue #5039
Issue #5615

It looks like there are a few others but it's not clear if that's what the root cause is? I searched for tickets with "mime" and "mimetype" as well as split up "mime type".

I haven't looked into it too much, but could there be a way to add another MimeTypeGuesser that uses a magic file file? Then it would just be a simple ->register call?

@fabpot
Copy link
Copy Markdown
Member

fabpot commented Feb 4, 2013

Seems like a good idea indeed. Do you want to work on a PR?

@JoshuaEstes
Copy link
Copy Markdown
Author

Sure, I can get you something after I'm done updating a few other things.

Thanks

@JoshuaEstes
Copy link
Copy Markdown
Author

Sorry it took so long to get this up here, it's very basic. The magic file comes from ftp://ftp.astron.com/pub/file/file-5.11.tar.gz and is just all the files combined. I looked at compiling the file into a magic.mgc file, however it was ~2MB which IMO is not good to keep a repo.

My thought is that, if users need something specific that they should be able to use this and not rely on the magic file here (might be worth deleting?). I'd be more than happen to add a cookbook entry if need be, however, I would like to do some more testing with this. If there is anything anyone can think of that I'm overlooking, please let me know.

$ file -v
file-5.11
magic file from /etc/magic:/usr/share/misc/magic

@raziel057
Copy link
Copy Markdown
Contributor

Why don't you simply add the possibility to pass the magic file path into the existing FileinfoMimeTypeGuesser?

I think there is no need to create another implementation (FileinfoMagicMimeTypeGuesser).

@JoshuaEstes
Copy link
Copy Markdown
Author

Could be worth a try, I'll take a look at it later when I'm not as busy.

fabpot added a commit to fabpot/symfony that referenced this pull request Apr 23, 2013
@fabpot
Copy link
Copy Markdown
Member

fabpot commented Apr 23, 2013

Closing in favor of #7809, where I implemented the possibility to configure the magic file from the existing class as suggested by @raziel057 . Adding a magic file in Symfony itself is not a good idea at the magic file format changed recently (according to the PHP documentation).

@fabpot fabpot closed this Apr 23, 2013
fabpot added a commit that referenced this pull request Apr 23, 2013
This PR was merged into the master branch.

Discussion
----------

[WIP][HttpFoundation] File mime types and extensions

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #5039, #6963, #5258, #7415, #5615
| License       | MIT
| Doc PR        | n/a

This pull request addresses most of the issues regarding mime types and extension on File instances.

I've also created an issue on the docs to add more documentation about how things work (see symfony/symfony-docs#2542).

Commits
-------

acc2b6a [HttpFoundation] updated the list of known mime types (sync from Apache)
f85cdd2 [HttpFoundation] fixed phpdoc
1aa68da [HttpFoundation] added a way to inject a custom magic file into FileinfoMimeTypeGuesser (closes #6963)
29b5413 [HttpFoundation] added some more phpdocs to clarify usage
ee784fb clarified how/when to use client or guessed mime-types and extensions on a File instance (closes #5039)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants