[Resolved] can't upload file with cred since plugin update
This support ticket is created 8 years, 3 months 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
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'].
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.
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;
}
}