感謝@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
不客氣,這裏是我的投票也。 –