How to verify that an image is really an "Image" or a PDF is really a "PDF document" during the upload?
I observed a hack attempt to upload some files with jpg extension which has a picture preview but when I tried to open this file in an editor I saw php codes!
My concern is about:
How can I verify that a file is a real file?
Im using laravel framework, I tested with image mimes validation as shown below:
$inputs = array('image'=>$request->file('file'));
$rules = array(
'image' => 'mimes:jpeg,jpg,png,gif|required|max:10000'
);
$validator = Validator::make($inputs, $rules);
if ($validator->fails()){
die('validation failed');
}else{
die('validation Passed');
}
But this validation always pass if I try to upload the invalid jpeg file with some php injected codes!