Skip Navigation

[Resolved] Empty upload file generate error

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 25 replies, has 2 voices.

Last updated by Minesh 1 year, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2611831

HI,

I have a cred where 'visitor' users can upload to a file upload field. I have a problem: when an empty file is uploaded (for example an empty word), it generates this error:

Warning: Undefined array key "wpcf-attachments" in /mnt/24oreventi_premio/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/classes/Form_Builder_Helper.php on line 1966

Warning: Object of class WP_Error could not be converted to int in /mnt/24oreventi_premio/wp-content/plugins/cred-frontend-editor/application/controllers/notification_manager/post.php on line 229

Warning: Object of class WP_Error could not be converted to int in /mnt/24oreventi_premio/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/models/Forms.php on line 365

Fatal error: Uncaught TypeError: Illegal offset type in /mnt/24oreventi_premio/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/models/Forms.php:365 Stack trace: #0 /mnt/ 24oreventi_premio/wp-content/plugins/cred-frontend-editor/application/controllers/notification_manager/post.php(348): CRED_Forms_Model->getAttachedData() #1 /mnt/24oreventi_premio/wp-content/plugins/cred-frontend- editor/application/models/form/post.php(548): CRED_Notification_Manager_Post->trigger_notifications() #2 /mnt/24oreventi_premio/wp-content/plugins/cred-frontend-editor/application/models/form/base.php( 453): CRED_Form_Post->notify() #3 /mnt/24hours_premium/wp-content/plugins/cred-frontend-editor/application/controllers/form_builder_base.php(44): CRED_Form_Base->print_form() #4 /mnt/ 24hours_premium/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/classes/CRED_Helper.php(1799): CRED_Form_Builder_Base->get_form() #5 /mnt/24hours_premio/wp-content/plugins/ cred-frontend-editor/library/toolset/cred/embedded/classes/CRED_Helper.php(2398): CRED_Helper::cred_form() #6 /mnt/24oreventi_premio/wp-includes/shortcodes.php(355): CRED_Helper:: credFormShortcode() #7 [internal function]: do_shortcode_tag() #8 /mnt/24hours_premium/wp-includes/shortcodes.php(227): preg_replace_callback() #9 /mnt/24hours_premium/wp-content/themes/generatepress_child_premium2023/functions .php(199): do_shortcode() #10 /mnt/24hours_reward/wp-includes/shortcodes.php(355): check_form_function() #11 [internal function]: do_shortcode_tag() #12 /mnt/24hours_reward/wp-includes /shortcodes.php(227): preg_replace_callback() #13 /mnt/24hours_premium/wp-content/themes/generatepress_child_premio2023/functions.php(132): do_shortcode() #14 /mnt/24hours_premio/wp-includes/shortcodes.php (355): check_cookie_exists_shortcode() #15 [internal function]: do_shortcode_tag() #16 /mnt/24hours_reward/wp-includes/shortcodes.php(227): preg_replace_callback() #17 /mnt/24hours_reward/wp-includes/class -wp-hook.php(308): do_shortcode() #18 /mnt/24hours_premium/wp-includes/plugin.php(205): WP_Hook->apply_filters() #19 /mnt/24hours_premium/wp-includes/post- template.php(255): apply_filters() #20 /mnt/24oreventi_premio/wp-content/themes/generatepress/content-page.php(73): the_content() #21 /mnt/24oreventi_premio/wp-includes/template. php(785): require('...') #22 /mnt/24hours_premium/wp-includes/template.php(718): load_template() #23 /mnt/24hours_premium/wp-includes/general-template.php (204): locate_template() #24 /mnt/24oreventi_premio/wp-content/themes/generatepress/inc/theme-functions.php(568): get_template_part() #25 /mnt/24oreventi_premio/wp-content/themes/generatepress /page.php(34): generate_do_template_part() #26 /mnt/24hours_premium/wp-includes/template-loader.php(106): include('...') #27 /mnt/24hours_premium/wp-blog- header.php(19): require_once('...') #28 /mnt/24hours_premium/index.php(17): require('...') #29 {main} thrown in /mnt/24hours_premium/wp -content/plugins/cred-frontend-editor/library/toolset/cred/embedded/models/Forms.php on line 365

In fact, if I load the same file from the media library, it gives me this error:
The file is empty. Upload something bigger. This error can also be caused by uploads being disabled in the php.ini file or by defining post_max_size as less than upload_max_filesize in php.ini.

is this type of error not handled by toolset?

#2611847

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to know first - Is file upload is disabled on your server?

Are you using media uploader to upload media or normal upload?

Here is how media uploader works with Toolset forms?
=> https://toolset.com/course-lesson/using-the-native-wordpress-media-manager-in-front-end-forms/#default-user-permissions-for-using-and-editing-existing-files

If you are using media uploader, As you may noticed there is no permission to guest (visitor) user and if you want to allow visitor user, you may have to allow upload_files permissions to guest user role.

#2611859
b562d961-92b9-479e-9d76-3e1956c68964.png

Hi,

I would like to know first - Is file upload is disabled on your server?
yes it is allowed, I can only upload files if they are not empty, the file I tried to upload was a new and empty file (and it weighed 0 bytes), I also tested it from admin and if the file is empty it reproduces the same error

Are you using media uploader to upload media or normal upload?
I'm using normal upload (i attached screenshot)

If you are using media uploader, As you may noticed there is no permission to guest (visitor) user and if you want to allow visitor user, you may have to allow upload_files permissions to guest user role.
How is this possible to give the guest a capacity? it's possible?

#2611949

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

But if filesizeis 0 then obviously it will throw the error.

I would like to know why you would like to upload the file with empty content?

Is that ok that if we check the file is not uploaded then we can display some default image that you would like?

#2611951

Hello,

yes I agree that it makes no sense to upload an image with filisize 0 but I would like to handle the error otherwise it will generate a fatal error on the page. how can i handle it?

#2612107

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Here is a sandbox site and can you please setup the form and send me the file you are trying to upload and then I will try to replicate with the same setup.

You can login to sandbox site using the following auto-login link:
- hidden link

#2612541

here is the test link hidden link

for the file, it would be enough to create a new word file and not write anything inside

unfortunately I can't replicate the error in this test site, in my site I have the fatal error when notifications are on for the submit form

Fatal error: Uncaught TypeError: Illegal offset type in /mnt/24oreventi_premio/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/models/Forms.php:365 Stack trace: #0 /mnt/ 24oreventi_premio/wp-content/plugins/cred-frontend-editor/application/controllers/notification_manager/post.php(348): CRED_Forms_Model->getAttachedData() #1

#2612635

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To allow or customize the mime types, you can use the native WordPress hook upload_mimes to add more mime types:
=> https://developer.wordpress.org/reference/hooks/upload_mimes/

For Example:
You can customize the following code as per your requirement.

function my_custom_mime_types( $mimes ) {
       
    // New allowed mime types.
    $mimes['svg']  = 'image/svg+xml';
    $mimes['svgz'] = 'image/svg+xml';
    $mimes['doc']  = 'application/msword'; 
   
    // Optional. Remove a mime type.
    unset( $mimes['exe'] );
   
    return $mimes;
}
add_filter( 'upload_mimes', 'my_custom_mime_types' );

You can add such custom code at:
=> Toolset > Settings > Custom code

More info:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

What if you add the above code and allow the doc type or any other extension you are trying to upload and check if that help you to resolve your issue.

#2612639

Hi,

I entered the code you provided but it didn't solve the problem.

The steps that reproduce the error are:
- Create post forms
- Add the file upload field as a field
- Add notification to form submit
- When completing the form, add a 0 byte word file and click submit
- fatal error

Fatal error: Uncaught TypeError: Illegal offset type in /mnt/24oreventi_premio/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/models/Forms.php:365 Stack trace: #0 /mnt/ 24oreventi_premio/wp-content/plugins/cred-frontend-editor/application/controllers/notification_manager/post.php(348): CRED_Forms_Model->getAttachedData() #1

If I insert a word file with a weight greater than 0 bytes I don't have this problem, I saw that in the test site you gave me if I insert an empty file word the error is handled correctly and does not create a fatal error.

Could it be a file permissions issue?

#2612671

Furthermore, the problem arises when I use a form to create new content, but if I do the same with a form to modify existing content, the fatal error does not occur.

#2612679

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I see the sandbox site I shared with you is using the PHP version 7.4.33 where you acknowledge that its working fine but not on your server where you are using PHP version 8.0.11.
=> hidden link

It seems its PHP version issue as from the code lines where the error happen is as follows from the file:

Fatal error: Uncaught TypeError: Illegal offset type in /mnt/24oreventi_premio/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/models/Forms.php:365 Stack trace: #0 /mnt/ 24oreventi_premio/wp-content/plugins/cred-frontend-editor/application/controllers/notification_manager/post.php(348): CRED_Forms_Model->getAttachedData() #1


=> plugins\cred-frontend-editor\application\controllers\notification_manager\post.php

if ( empty( $attached_data ) ) {
			$attached_data = $model->getAttachedData( $post_id );
		}

		// trigger for this event, if set
		if ( isset( $data[ 'event' ] ) ) {
			$this->event = $data[ 'event' ];
		} else {
			//Event can be set by check_for_notifications_by_status_switch call
			$this->event = ( isset( $this->event ) && ! empty( $this->event ) ) ? $this->event : false;
		}

		$notification = isset( $data[ 'notification' ] ) ? $data[ 'notification' ] : false;
		if (
			! $attached_data
			|| ! $notification
			|| ! isset( $notification->enable )
			|| ! $notification->enable
			|| empty( $notification->notifications )
		) {
			return;
		}

As you can noticed with the above code that when no $attached_data is available it returns nothing.

For a temporary time are you able to downgrade the PHP version to PHP 7.4.33 and check if that helps to fix the issue.

#2612687

Hi,

At the moment I can't change the php version but I tested it on another site with php 8 and it actually gives me the same error. Since at the moment I can't change the php version is there a way to make a temporary fix? (like a modification of this code or something similar)

#2612883

Hi, do you have any news? how can I do?

#2612907

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

We do not recommend to change the source code as when you update the plugin the changes you will make will be overridden.

I've escalated the issue to our next level support, please hold on for further updates. I will get in touch with you as soon as I see any update with our internal ticker.

#2612909

Hi,
ok thanks a lot
is there any other way I could use to upload the files in another way? instead of modifying the code do something temporary?