Mark Lyons
Mark Lyons

Reputation: 1422

PHP if image exceeds 1000px using getimagesize()

I'm using the remote method used in jQuery Validation.

I'm referring to a PHP file shown below:

<?php

$title = mysql_real_escape_string($right_form_url);
$size = getimagesize($title);
$size[3] = $width;

if ($width > 1000) {
   $output = false;
} else {
   $output = true;
}
echo json_encode($output);

?>

It never returns anything no matter how I put the $output variables. I've tried other PHP files that I know work in validation, so I think it has something to do with my IF statement, although I'm fairly certain the width is being declared correctly.

Upvotes: 0

Views: 291

Answers (2)

Kristian
Kristian

Reputation: 3479

You code is invalid. You are setting $size[3] = $width; which sould be $width = $size[0]; Two mistakes: 1. You were setting $size[3] to $width, but should set $width to $size[3] 2. $size[3] containts string valu t use with html image tag(height="yyy" width="xxx"), $size[0] conatins numeric value of width

Upvotes: 1

guiman
guiman

Reputation: 1334

I think i know your problem, here, the json_enconde function only supports data with UTF-8 encoding, then if your site uses another encoding, the function will return NULL, so try this:

<?php

$title = mysql_real_escape_string($right_form_url);
$size = getimagesize($title);
$size[3] = $width;

$output = true;    
if ($width > 1000) {
   $output = false;
}
echo json_encode(base64_encode($output));

?>

Upvotes: 0

Related Questions