如果使用数组中的值执行空数组

时间:2018-04-14 20:03:30

标签: php arrays

大家好我的网站上有一个简单的图片上传脚本,在上传图片之前需要进行一些检查。如果我尝试上传例如gif或大文件,将显示正确的错误消息,但图像仍将继续上传。虽然这不应该发生,因为要显示的错误消息,数组中必须有一个值? 有什么建议吗?

[routerLink]="[card.id, 'edit']"

2 个答案:

答案 0 :(得分:0)

$ error中的密钥未包含在引号中。例如

if (!in_array($imageExt, $allowed)) {
    $errors['ext'] = "Invalid file format";
}
// checks if there are any errors with the image
if (!$imageError === 0) {
    $errors['image'] = "Error with your file";
}
// checks if the file size is less than 1MB
if (!$imageSize < 1000000) {
     $errors['size'] = "File is to big";
}
// check if the image width is less than or equal to 1024px
if (!$imageWidth <= 1024) {
    $errors['width'] = "Image width is limited to 1024px for layout purposes";
}
// check if image  height is less than or equal to 768 pixels
if (!$imageHeight <= 768) {
    $errors['height'] = "Image height is limited to 768px for layout purposes";
}

这可能会解决您的错误。

答案 1 :(得分:0)

从比较中删除!

!$imageSize < 1000000被视为:

(!$imageSize) < 1000000

如果您的$imageSize为500,!$imageSize为false,因此0为数字。

与除in_array之外的所有其他比较相同。