Keyword

no error message on upload max filesize

  • sherwin anthony
  • sherwin anthony's Avatar Topic Author
  • Offline
  • New Member
More
3 weeks 3 hours ago - 3 weeks 1 hour 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 weeks 1 hour ago by sherwin anthony.

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

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
2 weeks 5 days ago - 2 weeks 5 days ago #176310 by Fotis
Replied by Fotis 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...'.

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member
Last edit: 2 weeks 5 days ago by Fotis.

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

  • sherwin anthony
  • sherwin anthony's Avatar Topic Author
  • Offline
  • New Member
More
2 weeks 5 days 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.

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
2 weeks 3 days ago #176332 by Fotis
Replied by Fotis 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.

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

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

  • sherwin anthony
  • sherwin anthony's Avatar Topic Author
  • Offline
  • New Member
More
2 weeks 3 hours 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