我的图片上传器设置了一条错误消息,以便在上传的图片大于特定尺寸时显示。但是,如果我上传的内容非常大,则会绕过错误消息,并且用户会看到POST Content-Length超出错误消息,我不希望他们看到。有人可以帮我弄清楚为什么太大的图像文件没有显示错误信息?
以下是上传照片时调用的验证功能:
//------------------------------
private function _verify($fn) {
//------------------------------
global $_WEBCONFIG;
$isValid = TRUE;
$userID = isset($_POST["hidId"]) ? (int)$_POST["hidId"] : 0;
$this->record2->p_id = $this->proId;
$fieldName = "txtName";
$fieldValue = SanitizeData($_POST[$fieldName]);
if (!$fieldValue || strlen($fieldValue = trim($fieldValue)) == 0) {
$this->record2->i_name = '';
} else {
$this->record2->i_name = $fieldValue;
}
$fieldName = "fleImage";
if (isset($_FILES[$fieldName]) && strlen($_FILES[$fieldName]['name']) > 0) {
$fieldValue = $_FILES[$fieldName]['name'];
$file_ext = strtolower(GetExtName($fieldValue));
$arExts = explode(",", VALID_IMGS);
if (!in_array($file_ext, $arExts)) {
$this->errors[] = "Invalid Image Format. (Allowed image types: " . VALID_IMGS . ")";
$isValid = FALSE;
} else {
$size = getimagesize($_FILES[$fieldName]['tmp_name']);
if ($size[0] < $_WEBCONFIG['THUMB_WIDTH'] || $size[1] < $_WEBCONFIG['THUMB_HEIGHT']) {
$this->errors[] = "Invalid Image Size. (Image Dimensions: " . $_WEBCONFIG['IMAGE_WIDTH'] . " x " . $_WEBCONFIG['IMAGE_HEIGHT'] . " or larger)";
$isValid = FALSE;
}
$imageSize = filesize($_FILES[$fieldName]['tmp_name']);
if ($imageSize > 16777216){
$this->errors[] = "Invalid File Size. File size must be smaller than 128 MB.";
$isValid = FALSE;
}
}
} else if ($fn == 0) {
$this->errors[] = "Please upload an Image (Image Dimensions: " . $_WEBCONFIG['IMAGE_WIDTH'] . " x " . $_WEBCONFIG['IMAGE_HEIGHT'] . " or larger.)";
$isValid = FALSE;
}
$fieldName = "txtOrder";
$fieldValue = SanitizeData($_POST[$fieldName]);
if (strlen($fieldValue = trim($fieldValue)) == 0) {
$this->record2->i_sort_id = 99999;
} else {
$this->record2->i_sort_id = $fieldValue;
}
return $isValid;
}//end function
我上传的图像尺寸绕过了错误信息是37.4 MB
答案 0 :(得分:3)
该错误很可能是由服务器发送的。服务器将在php.ini中设置可以配置的设置。例如
memory_limit = 32M
upload_max_filesize = 10M
post_max_size = 20M
php.ini文件通常存储在/etc/php.ini或/etc/php.d/cgi/php.ini或/usr/local/etc/php.ini中,但大多数Web主机提供了一个选项在控制面板中编辑此文件