Keyword

no error message on upload max filesize

  • sherwin anthony
  • sherwin anthony's Avatar Topic Author
  • Offline
  • New Member
More
3 years 9 months ago - 3 years 9 months ago #176305 by sherwin anthony
no error message on upload max filesize was created by sherwin anthony
My website allows users to upload a K2 item on the frontend. I have set the following php configuration on the server:

upload_max_filesize = 2M
post_max_size = 64M
memory_limit=128M
error_reporting=E-ALL

Joomla 3.9.19
K2: v2.10.3
php: 7.3.18

I also enable error displays

The problem is that when a user uploads an image file which is greater than 2M, the form still accepts the content without displaying any error, and the default "Item saved" is displayed. However, the image is not displayed (probably because it's more than 2M).

I think that the restriction on the upload size is working, but how can I display an error message to show that the image exceeds the maximum size?
Last edit: 3 years 9 months ago by sherwin anthony.

Please Log in or Create an account to join the conversation.

More
3 years 9 months ago - 3 years 9 months ago #176310 by JoomlaWorks
Replied by JoomlaWorks on topic no error message on upload max filesize
Try this...

Edit this file github.com/getk2/k2/blob/c90e4d92d56b1a495d2c47cba9d5c291f4559a12/administrator/components/com_k2/models/item.php#L358-L360 and replace the marked lines from:
if ($files['image']['error'] == 0) {
    $handle->clean();
}

to:
if ($handle->processed) {
    $handle->clean();
} else {
    $app->enqueueMessage($handle->error, 'error');
}

You can replace "$handle->error" with a generic message if you want, e.g. 'There was a problem uploading your item image, please try again...'.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 3 years 9 months ago by JoomlaWorks.

Please Log in or Create an account to join the conversation.

  • sherwin anthony
  • sherwin anthony's Avatar Topic Author
  • Offline
  • New Member
More
3 years 9 months ago #176320 by sherwin anthony
Replied by sherwin anthony on topic no error message on upload max filesize
Thanks.

I already replaced the lines, but i get the following error:

0
syntax error, unexpected 'public' (T_PUBLIC)

Ok, so at first I copied the entire code from the link and made the replacement. That's when I get the error

Next, I just use the original item.php file and tried to replace only the specified lines. Then I get a blank white screen. After a few clicks, the same error message appears.

I also enabled display_errors from PHP and Joomla Error reporting to Maximum. The problem is still there

Please Log in or Create an account to join the conversation.

More
3 years 9 months ago #176332 by JoomlaWorks
Replied by JoomlaWorks on topic no error message on upload max filesize
Make sure you're editing the right file.

Restore any changes and re-apply the replacement.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • sherwin anthony
  • sherwin anthony's Avatar Topic Author
  • Offline
  • New Member
More
3 years 9 months ago #176374 by sherwin anthony
Replied by sherwin anthony on topic no error message on upload max filesize
Hi. I already edited the correct file. I still get the same result. When the user uploads an image which is greater than the max file size, there is still no error message printed when the Save button is clicked. When the close button is clicked the item is saved but the image is not displayed. But when I try to upload an image that is greater than the POST_MAX_SIZE, an error message will be printed.

This is now how the code looks like:

// Generic image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $params->get('imagesQuality');
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_Generic';
$imageWidth = $params->get('itemImageGeneric', '300');
$handle->image_x = $imageWidth;
$handle->process($savepath);

if ($handle->processed) {
$handle->clean();
} else {
$app->enqueueMessage('There was a problem uploading your item image, please try again...', 'error');
}
} else {
$app->enqueueMessage(JText::_('K2_IMAGE_WAS_NOT_UPLOADED'), 'notice');
}
}

if (JRequest::getBool('del_image')) {
$current = JTable::getInstance('K2Item', 'Table');
$current->load($row->id);
$filename = md5("Image".$current->id);

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum