Skip Navigation

[Resolved] can't upload file with cred since plugin update

This support ticket is created 8 years ago. There's a good chance that you are reading advice that it now obsolete.

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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by q1 8 years ago.

Assisted by: Shane.

Author
Posts
#401561

q1
Screen Shot 2016-05-25 at 14.10.43.png

Hi,

I noticed that since I updated the toolset plugin (CRED) I cannot upload files anymore. I get the following error:

Notice: Undefined index: wpcf-main-image in .../wp-content/plugins/cred-frontend-editor/embedded/classes/Form_Builder_Helper.php on line 2550

When I debug the file I see that the name of the input has the prefix "wpcf-" but it is not the same as the key in the array of $out_['fields']['post_fields'].

Here's the form content code for the input:

[cred_field field='main-image' post='project' value='' urlparam='']

I also attached a screenshot of the debug window with the variables content so you can see what I mean.

Is this a bug of the plugin? Because before the update the upload was working. I am currently using Toolset CRED v1.6 and Toolset Types v2.0.1. and Toolset Access v2.0.

Note: Since the update I also cannot find the debug information link.

Thank you for your help!

#401733

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Thank you for contacting our support forum.

Would it be possible for you to check with your hosting provider to see which version of php your website is running on ?

The issue could be caused by an older version of php.

Looking forward to hearing from you soon.
Thanks,
Shane

#401809

q1

Hi,

thank you for your reply.

I am currently working on my local machine. It has PHP 5.6.18-1 on it.

Best Regards,
Q1

#401935

q1

Hi,

I found the cause of the error. I have the following function/hook which checks if the selected file matches the constraints (dimension, filesize) and then returns the file or an error message which should be displayed. Now the issue is that before the update the upload worked fine but now I get the php error message.

Here's my code:

add_filter('wp_handle_upload_prefilter', 'tc_handle_upload_prefilter');
function tc_handle_upload_prefilter($file)
{
    $img = getimagesize($file['tmp_name']);

    if ($img != 0) {
        $minimum = array('width' => '600', 'height' => '400'); // width and height in pixel
        $maximum = array('filesize' => 10); // max filesize in megabytes
        $width = $img[0];
        $height = $img[1];
        $filesize = round($file['size'] / (1024 * 1024), 1);

        if ($filesize > $maximum['filesize'])
            return array("error" => "File size is too large. Maximum file size is {$maximum['filesize']}px. Uploaded file size is $filesize MB");
        else if ($width < $minimum['width'])
            return array("error" => "Image dimensions are too small. Minimum width is {$minimum['width']}px. Uploaded image width is $width px");
        elseif ($height < $minimum['height'])
            return array("error" => "Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px");
        else
            return $file;
    } else {
        return $file;
    }
}

Is there a (new) way to do this? Thanks!

#401957

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Would you mind providing me with admin access to the website so that I can test this out ?

The error that you are getting is just a notice and i'm not seeing why it should break the form completely 🙁

Did you try uploading an image with the correct dimension that wouldn't trigger the hook ?

Please let me know.
Thanks,
Shane

#402152

q1

Hi,

when uploading a correct image file the upload and form submission works fine.

Yes, it is a notice. I think that the upload isn't related to the notice but more because of the

wp_handle_upload_prefilter

hook which triggers the file check. I am using now the

cred_form_validate

hook to check the attached files. It seems to work now.

Currently the site is only on my local machine but I can set up a test-environment for you if still needed for further testing.

Thanks a lot for your reply!

#402263

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

That's since our cred hook resolves the issue 🙂

Is everything working correctly now ?

If so could you mark this ticket as resolve 🙂

Thanks,
Shane

#402702

q1

Hi,

it seems so 🙂

thanks for your time and help!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.