Laravel 和干预 - 如何禁止上传大图

Laravel and Intervention - How to disallow upload of big images

我的 Laravel 应用程序上有这个上传控制器。 它允许上传 <2Mb 大小的图像。问题是我有几个jpg文件压缩后是900KB,打开后是69MB,尺寸为6016×4016px,分辨率为300dpi。

如何检测尺寸和分辨率并提前停止上传?

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\File;


class UploadController extends Controller {


public function store()
    {

        $uploadedimage = array();

        $type      = Input::get('type');
        $table     = Input::get('table');
        $folder    = Input::get('folder');
        $extkey    = Input::get('extkey');
        $record    = Input::get('record');
        $tipo      = Input::get('tipo');
        $adduser   = Input::get('adduser');

        foreach (Input::file('image') as $image) {

            $oldname = $image->getClientOriginalName();
            $vowels = array("#", "@", "+", "à", "è", "é", "ì", "ò", "ù", ";", ",", "?", "*", '$', "!", "(", ")", "/", '"', "'", "%", "£", "<", ">", "&");
            $newname = str_replace($vowels, "", $oldname);

            $imagename = time()."-".$newname;
            $uploadflag = $image->move('repository/'.$folder, $imagename);

            if($uploadflag){
                $uploadedimage[] = $imagename;
            }

        }

        foreach ($uploadedimage as $value) {

            if($type == 1) {
                $tab = explode("|", $extkey);

                if($adduser == 1){
                DB::table($table)->insert(array(
                        $tab[1].'_id'      => $tab[0],
                        'active'           => 1,
                        'ordine'           => 100,
                        $record            => $value,
                        'user_id'          => Auth::id()
                    ));
                } else {
                    DB::table($table)->insert(array(
                        $tab[1].'_id'      => $tab[0],
                        'active'           => 1,
                        'ordine'           => 100,
                        $record            => $value
                    ));
                }
            } else {
                DB::table($table)->where('id', $extkey)->update(array($record => $value));
            }

        }

        return Response::json(['success' => 'true', 'images' => $uploadedimage ]);

    }

使用dimensions validation rule:

public function store(Request $request)
{
    $request->validate([
        'image' => 'dimensions:min_width=100,min_height=200',
    ]);
}