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
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.
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.
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?
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?
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:
- versteckter Link
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.
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.
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.
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.
=> versteckter 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
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)
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.