Skip to content

Instantly share code, notes, and snippets.

@andrewflash
Created November 23, 2013 05:29
Show Gist options
  • Save andrewflash/7611176 to your computer and use it in GitHub Desktop.
Save andrewflash/7611176 to your computer and use it in GitHub Desktop.
The Real Way to Check Uploaded File Type
<?php
// Here we specify all the type of files we want to accept
$extension = array("application/pdf", "image/jpeg", "image/png", "image/gif");
if(isset($_POST['submit'])){
exec("file -i ".$_FILES['inputName']['tmp_name'], $output);
$type = explode(':', (string)$output[0]);
}
// Here we check our file with our needs
if (isset($_FILES['inputName']) &&
$_FILES['inputName']['error'] == UPLOAD_ERR_OK &&
$_FILES['inputName']['size'] <= 10000000 &&
in_array(trim($type[1]), $extension)){
var_dump($_FILES['inputName']['tmp_name']);
}else{
die("File Error");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment