tinram / file-identifier Goto Github PK
View Code? Open in Web Editor NEWIdentify a file via MIME type and file signature detection.
License: GNU General Public License v3.0
Identify a file via MIME type and file signature detection.
License: GNU General Public License v3.0
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?"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.