php - Laravel check if image path string is image -


i'm passing image path paremeter when link clicked, need check if image security reasons.

when try code, $filename '15612.jpg':

$filename = $_get['filename'];  $image = array('file' => file::get('unverified-images/'.$filename)); $rules = array('file' => 'image'); $validator = validator::make($image, $rules);  if ($validator->fails()) {   session::flash('error', 'not image');    return redirect::to('controlpanel'); } 

all .jpg files have tested give 'not image', when try .txt file doesn't give error, why this? i'm guessing im doing wrong, validator supposed fail when it's not image, right?

i know validator takes input::file() instead of file::get(), how can use if i'm not using form?

this may case of avoiding validator, , doing check yourself, do:

$allowedmimetypes = ['image/jpeg','image/gif','image/png','image/bmp','image/svg+xml']; $contenttype = mime_content_type('path/to/image');  if(! in_array($contenttype, $allowedmimetypes) ){   session::flash('error', 'not image');    return redirect::to('controlpanel'); } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -