GithubHelp home page GithubHelp logo

josantonius / php-mime-type Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 8.0 1.46 MB

PHP library to get MIME types from extensions

Home Page: https://josantonius.dev

License: MIT License

PHP 100.00%
headers-mime composer php mime-type mime-types mimetype

php-mime-type's People

Contributors

derrickobedgiu1 avatar josantonius avatar masnathan avatar peter279k avatar scicali avatar touchweb-vincent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

php-mime-type's Issues

I would advise against using this

With this library you are getting the mime type based on the file extension and not the actual mime type of the file, based on the file content (the actual binary data), which is s HUGE security problem. If someone uses this with form submitted files, they are introducing a massive security hole in their code as the extension of the file can be easily changed by anyone so that they can easily upload a file.

You must place a warning in your readme so that this is not used for form upload purposes or for public facing projects.

Have a look at how PHP does this with the function mime_content_type and look for actual code and you will see that it actually opens the file to read the first bytes.

I realize that you specify that this library determines the mime type from an extension, but you need to warn people about the dangers of that in case someone less experienced uses this for production ready projects where security is very important.

Hope this helps and does not get deleted.

First ! :)

Thanks you for this library ;) You did a great job.

Hope i will be able to help in any kind of maner.

Woff2 is missing

".woff2": "application/x-font-woff2",

It's a common missing since woff2 is quite recent.

PHP 7 only, in 2017, is not a good idea.

Hello,

Since there is millions of systems which are PHP 5 only (at least until the end of 2017 - because of native PHP support from Debian 8 - the latest stable released of Debian - which run now, PHP 5.6.29).

I advice you to make your library PHP 5.6 compliant, by using with awesome one :

if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
// PHP7 only stuff
}

Then, there is some rewriting to do :

  • declare(strict_types=1); (PHP 7 only)
  • remove : :type from static functions (PHP 7 only) - i advice you to completely remove this if you won't deal with 2 classes
  • inside getMimeFromExtension, change for : return (isset(static::$mimeTypes[$ext]) ? static::$mimeTypes[$ext] : "undefined"); (?? is PHP 7 only)

I'm currently rewriting all your functions to make it works under PHP 5.6. I will be maybe fork it on Github if i got times.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.