Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Validate Uploaded Image Dimensions #13428

Merged
merged 1 commit into from
May 9, 2016
Merged

[5.2] Validate Uploaded Image Dimensions #13428

merged 1 commit into from
May 9, 2016

Conversation

themsaid
Copy link
Member

@themsaid themsaid commented May 4, 2016

This PR adds a new validation rule:

// Multiple rules
$rules = ['image' => 'image_dimensions:width=100,min_height=30'];

// Single rule
$rules = ['image' => 'image_dimensions:ratio=3/2'];

Available rules are:

  • min_width
  • min_height
  • max_width
  • max_height
  • width
  • height
  • ratio

if (isset($parameters['ratio'])) {
list($numerator, $denominator) = array_pad(sscanf($parameters['ratio'], '%d/%d'), 2, 1);

return eval("return {$numerator}/{$denominator};") == $width / $height;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eval?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeh, there's no way you need an eval in there

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was using it for a different implementation but forgot to change. Will fix.

Sent from my iPhone

On May 4, 2016, at 9:09 PM, Graham Campbell notifications@github.com wrote:

In src/Illuminate/Validation/Validator.php:

  •    if (
    
  •        isset($parameters['width']) && $parameters['width'] != $width ||
    
  •        isset($parameters['min_width']) && $parameters['min_width'] > $width ||
    
  •        isset($parameters['max_width']) && $parameters['max_width'] < $width ||
    
  •        isset($parameters['height']) && $parameters['height'] != $height ||
    
  •        isset($parameters['min_height']) && $parameters['min_height'] > $height ||
    
  •        isset($parameters['max_height']) && $parameters['max_height'] < $height
    
  •    ) {
    
  •        return false;
    
  •    }
    
  •    if (isset($parameters['ratio'])) {
    
  •        list($numerator, $denominator) = array_pad(sscanf($parameters['ratio'], '%d/%d'), 2, 1);
    
  •        return eval("return {$numerator}/{$denominator};") == $width / $height;
    
    yeh, there's no way you need an eval in there


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np ;)

@taylorotwell taylorotwell merged commit 2a487e4 into laravel:5.2 May 9, 2016
@taylorotwell
Copy link
Member

Guess we'll also need a new language line and docs entry for this.

@themsaid themsaid deleted the validate-image branch May 9, 2016 13:50
@themsaid
Copy link
Member Author

themsaid commented May 9, 2016

Will take care of that in a couple of hours :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants