2011-12-28 80 views
0

我正在使用jQuery Validation中使用的远程方法。PHP如果图像超过1000像素使用getimagesize()

我指的是如下图所示的PHP文件:

<?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); 

?> 

它不会返回任何东西不管我怎么把$output变量。我已经尝试了其他PHP文件,我知道它们在验证中工作,所以我认为它与我的IF语句有关,尽管我相当肯定宽度是正确声明的。

+0

您是否启用了错误报告?你在做任何类型的调试吗?例如,$ right_form_url包含什么? – 2011-12-28 18:33:56

+0

您的链接似乎不起作用。 – 2011-12-28 18:34:55

+1

是一个拼写错误还是将空的'$ width'变量赋给'$ size [3]'? – arma 2011-12-28 18:35:41

回答

1

你的代码无效。要设置$size[3] = $width;这是前人的精力$width = $size[0]; 两个错误: 1.你被设置$size[3]$width,但应设置与HTML图像标记(高度=“YYY”宽度$width$size[3] 2. $size[3] containts串VALU T选用=” xxx“),$size[0] conatins宽度的数值

+0

这是行不通的:( – 2011-12-28 18:42:52

+0

)试试''output = array(“result”=> true)'和'$ output = array(“result”=> false)'而不是。只有'json_endode(true)'或者'json_encode(array(“result”=> true))''也许那是行不通的。 – Kristian 2011-12-28 18:48:18

+0

如果你看原文的评论,那是因为'mysql_escape_string'函数。那么''size [0]'是你的答案,所以我会选择你的。 – 2011-12-28 18:51:13

0

我想我知道你的问题,在这里,json_enconde功能只支持UTF-8编码的数据,那么如果您的网站使用其他的编码,该函数将返回NULL,那么试试这个:

<?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)); 

?> 
相关问题