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
Post a Comment