簡體   English   中英

在laravel 4中上傳之前如何檢查圖像尺寸

[英]how to check image dimensions before upload in laravel 4

我是Laravel 4的新手。

我想上傳最大尺寸為800x600的照片。

請幫助指導我!

您可以簡單地使用getImageSize()作為

list($width, $height) = getimagesize(Input::file('file'));

像這樣檢查驗證

if ($validator->passes() && correct_size(Input::file('file'))) {
    // do something
}

創建這樣的驗證功能,無論您選擇哪種模型

public function correct_size($photo) {
    $maxHeight = 100;
    $maxWidth = 100;
    list($width, $height) = getimagesize($photo);
    return ( ($width <= $maxWidth) && ($height <= $maxHeight) );
}

您可以決定是否要靜態使用它。 但是,如果您想使用不帶依賴項的相同驗證來檢查其他上載,我的建議不是靜態定義它。

在表單驗證中進行如下檢查。

'avatar' => 'dimensions:min_width=100,min_height=200'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM