感谢@maytham对他的评论指出这我在正确的方向。
我发现的是图像干涉本身不会进行任何验证。所有图像验证必须在传递到Image上传之前完成。感谢Laravel内置的验证器,如image
和mime
类型,这使得图像验证非常简单。这是我现在在将文件输入传递给Image Intervention之前先验证文件输入的地方。
验证检验处理干预Image
课前:
Route::post('/upload', function()
{
$postData = $request->only('file');
$file = $postData['file'];
// Build the input for validation
$fileArray = array('image' => $file);
// Tell the validator that this file should be an image
$rules = array(
'image' => 'mimes:jpeg,jpg,png,gif|required|max:10000' // max 10000kb
);
// Now pass the input and rules into the validator
$validator = Validator::make($fileArray, $rules);
// Check to see if validation fails or passes
if ($validator->fails())
{
// Redirect or return json to frontend with a helpful message to inform the user
// that the provided file was not an adequate type
return response()->json(['error' => $validator->errors()->getMessages()], 400);
} else
{
// Store the File Now
// read image from temporary file
Image::make($file)->resize(300, 200)->save('foo.jpg');
};
});
希望这有助于。
你可能需要看看这个https://laracasts.com/discuss/channels/general-discussion/validating-an-image-laravel-5和这个http://tutsnare.com/upload-files-in-laravel/据我所知干预中没有内容验证。 –
谢谢@maytham您的评论当然帮助我指出了正确的方向。我已经发布了我现在使用的解决方案。 :) – Neel
不客气,这里是我的投票也。 –