Giter Site home page Giter Site logo

tinram / file-identifier Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 4.0 50 KB

Identify a file via MIME type and file signature detection.

License: GNU General Public License v3.0

PHP 100.00%
signature-detection files file-identification magic-bytes file-header signatures file-signature

file-identifier's People

Contributors

tinram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

file-identifier's Issues

Multiple File Upload

I like it, I tried various filetypes the outputs were different. I even tried to fool your script and change the extension of an EXE file to a PNG file, and $r['fileinfo'] still returned "EXE (MZ: DOS / Windows)".

I'm having problems when I read from multiple [type="file"] inputs. I had to split $r['mimeinfo'] to just return the mimetype:

$fID = new FileIdentifier( $_FILES[ 'file' ][ 'tmp_name' ][ $key ] );
$IDr = $fID->getResult();
if ( $IDr ) {
  $mimeType = end( explode( ': ', $IDr[ 'mimeinfo' ] ) );
} else {
  print( json_encode( array( 'status' => 'danger', 'alertMsg' => 'Cannot detect signature for file: ' . $_FILES[ 'uploadimg' ][ 'name' ][ $key ], 'code' => 0 ) ) );
  exit();
}

It says the first file (presumably) because of having [$key] is invalid, even though when I tested it as a single file upload validating as an image, it came back valid.

if ( $mimeType !== 'image/jpeg' || $mimeType !== 'image/png' ) {
  // I've tried != and && in various combinations, still detects a real png image invalid.
  print( json_encode( array( 'status' => 'danger', 'alertMsg' => $_FILES[ 'uploadimg' ][ 'name' ][ $key ] . ' is not a true image', 'code' => 0 ) ) );
  exit();
}

And yes, I have this in a foreach() loop, the first thing I'm doing is making sure if the file is a PNG/JPEG/JPG, your script is "the nosy sibling" asking "Are you really?"

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.