Reputation: 1679
My image uploader has an error message set to display when images that are uploaded are greater than a certain size. However, if I upload something that is REALLY big, the error message gets bypassed and the user is stuck seeing the POST Content-Length exceeded error message that I don't want them to see. Can someone please help me figure out why image files that are too large don't get the error message displayed?
Here is the verify function that gets called when a photo is uploaded:
//------------------------------
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
The image size I am uploading that bypasses the error message is 37.4 MB
Upvotes: 1
Views: 2315
Reputation: 1115
that error is most probably sent by the server. the server will have settings in the php.ini which could be configured. eg
memory_limit = 32M
upload_max_filesize = 10M
post_max_size = 20M
the php.ini file is usually stored in /etc/php.ini or /etc/php.d/cgi/php.ini or /usr/local/etc/php.ini but most web hosts provide an option to edit this file within the control panel
Upvotes: 3