MyBB Community Forums

Full Version: After upgrade to 1.8.29 Full edit of posts show HTTP ERROR 500
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
After upgrading to 1.8.29, the Full edit of posts shows HTTP ERROR 500 page but quick edit works.\

I think this i due to adding of bank pipe plugin variable on function_upload.php file. See below error. Line 829 shows an error. Thi error is also shown on error_log.

[attachment=44742]

Please guide.
Thank you.
Is this an edit you've applied yourself? It's putting an else statement before a elseif which isn't valid PHP syntax. What are you trying to do with the code addition? You may just need to put it after the elseif block instead, but not sure what you're trying to achieve with it.
Actually, I copied from the previous version 1.8 26 in which full edit of the post, new reply and New Thread works fine. Because this bankpipe related code doesn't add after upgradation to the core file.

Also, I Checked on a fresh mybb and bankpipe copy, but the issue is also present there.

But after upgrading to 1.8.29 full edit of the post and creation of a new thread did not work after adding that variable. 


Below is 1.8.29  function_upload.php file one code portion. where full edit, new reply and post new thread gives error.
**
 * Process adding attachment(s) when the "Add Attachment" button is pressed.
 *
 * @param int $pid The ID of the post.
 * @param array $forumpermission The permissions for the forum.
 * @param string $attachwhere Search string "pid='$pid'" or "posthash='".$db->escape_string($mybb->get_input('posthash'))."'"
 * @param string $action Where called from: "newthread", "newreply", or "editpost"
 *
 * @return array Array of errors if any, empty array otherwise
 */
function add_attachments($pid, $forumpermissions, $attachwhere, $action=false)
{
	global $db, $mybb, $editdraftpid, $lang;

	$ret = array();

	if($forumpermissions['canpostattachments'])
	{
		$attachments = array();
		$fields = array ('name', 'type', 'tmp_name', 'error', 'size');
		$aid = array();

		$total = isset($_FILES['attachments']['name']) ? count($_FILES['attachments']['name']) : 0;
		$filenames = "";
		$delim = "";
		for($i=0; $i<$total; ++$i)
		{
			foreach($fields as $field)
			{
				$attachments[$i][$field] = $_FILES['attachments'][$field][$i];
			}

			$FILE = $attachments[$i];
			if(!empty($FILE['name']) && !empty($FILE['type']) && $FILE['size'] > 0)
			{
				$filenames .= $delim . "'" . $db->escape_string($FILE['name']) . "'";
				$delim = ",";
			}
		}

		if ($filenames != '')
		{
			$query = $db->simple_select("attachments", "filename", "{$attachwhere} AND filename IN (".$filenames.")");

			while ($row = $db->fetch_array($query))
			{
				$aid[$row['filename']] = true;
			}
		}

		foreach($attachments as $FILE)
		{
			if($err = check_parse_php_upload_err($FILE))
			{
				$ret['errors'][] = $err;
				$mybb->input['action'] = $action;
			}
			else if(!empty($FILE['name']) && !empty($FILE['type']))
			{
				if($FILE['size'] > 0)
				{
					$filename = $db->escape_string($FILE['name']);
					$exists = !empty($aid[$filename]);

					$update_attachment = false;
					if($action == "editpost")
					{
						if($exists && $mybb->get_input('updateattachment') && ($mybb->usergroup['caneditattachments'] || $forumpermissions['caneditattachments']))
						{
							$update_attachment = true;
						}
					}
					else
					{
						if($exists && $mybb->get_input('updateattachment'))
						{
							$update_attachment = true;
						}
					}
					
					if(!$exists && $mybb->get_input('updateattachment') && $mybb->get_input('updateconfirmed', MyBB::INPUT_INT) != 1)
					{
						$ret['errors'][] = $lang->sprintf($lang->error_updatefailed, $filename);
					}
					else
					{
						$attachedfile = upload_attachment($FILE, $update_attachment);

						if(!empty($attachedfile['error']))
						{
							$ret['errors'][] = $attachedfile['error'];
							$mybb->input['action'] = $action;
						}
/* + PL:bankpipe + */ else
/* + PL:bankpipe + */ {
/* + PL:bankpipe + */ $args = ['attachedfile' => $attachedfile];
/* + PL:bankpipe + */ $GLOBALS['plugins']->run_hooks('bankpipe_core_add_attachment', $args);
/* + PL:bankpipe + */ }
						else if(isset($attachedfile['aid']) && $mybb->get_input('ajax', MyBB::INPUT_INT) == 1)
						{
							$ret['success'][] = array($attachedfile['aid'], get_attachment_icon(get_extension($filename)), $filename, get_friendly_size($FILE['size']));
						}
					}
				}
				else
				{
					$ret['errors'][] = $lang->sprintf($lang->error_uploadempty, htmlspecialchars_uni($FILE['name']));
					$mybb->input['action'] = $action;
				}
			}
		}
	}

	return $ret;
}
If I remove, 'else' from the below 1.8.29 function_upload.php code, then there is no any post edit, reply, and new thread creation  related issue. working fine.
I don't know whether the removal of code 'else' will create an issue or not on board.

else if(isset($attachedfile['aid']) && $mybb->get_input('ajax', MyBB::INPUT_INT) == 1)
{
$ret['success'][] = array($attachedfile['aid'], get_attachment_icon(get_extension($filename)), $filename, get_friendly_size($FILE['size']));
}



Below is 1.8.26 function_upload.php code in which full edit, new reply, and post new thread working fine.

**
 * Process adding attachment(s) when the "Add Attachment" button is pressed.
 *
 * @param int $pid The ID of the post.
 * @param array $forumpermission The permissions for the forum.
 * @param string $attachwhere Search string "pid='$pid'" or "posthash='".$db->escape_string($mybb->get_input('posthash'))."'"
 * @param string $action Where called from: "newthread", "newreply", or "editpost"
 *
 * @return array Array of errors if any, empty array otherwise
 */
function add_attachments($pid, $forumpermissions, $attachwhere, $action=false)
{
	global $db, $mybb, $editdraftpid, $lang;

	$ret = array();

	if($forumpermissions['canpostattachments'])
	{
		$attachments = array();
		$fields = array ('name', 'type', 'tmp_name', 'error', 'size');
		$aid = array();

		$total = isset($_FILES['attachments']['name']) ? count($_FILES['attachments']['name']) : 0;
		$filenames = "";
		$delim = "";
		for($i=0; $i<$total; ++$i)
		{
			foreach($fields as $field)
			{
				$attachments[$i][$field] = $_FILES['attachments'][$field][$i];
			}

			$FILE = $attachments[$i];
			if(!empty($FILE['name']) && !empty($FILE['type']) && $FILE['size'] > 0)
			{
				$filenames .= $delim . "'" . $db->escape_string($FILE['name']) . "'";
				$delim = ",";
			}
		}

		if ($filenames != '')
		{
			$query = $db->simple_select("attachments", "filename", "{$attachwhere} AND filename IN (".$filenames.")");

			while ($row = $db->fetch_array($query))
			{
				$aid[$row['filename']] = true;
			}
		}

		foreach($attachments as $FILE)
		{
			if($err = check_parse_php_upload_err($FILE))
			{
				$ret['errors'][] = $err;
				$mybb->input['action'] = $action;
			}
			else if(!empty($FILE['name']) && !empty($FILE['type']))
			{
				if($FILE['size'] > 0)
				{
					$filename = $db->escape_string($FILE['name']);
					$exists = $aid[$filename];

					$update_attachment = false;
					if($action == "editpost")
					{
						if($exists && $mybb->get_input('updateattachment') && ($mybb->usergroup['caneditattachments'] || $forumpermissions['caneditattachments']))
						{
							$update_attachment = true;
						}
					}
					else
					{
						if($exists && $mybb->get_input('updateattachment'))
						{
							$update_attachment = true;
						}
					}

					$attachedfile = upload_attachment($FILE, $update_attachment);

					if(!empty($attachedfile['error']))
					{
						$ret['errors'][] = $attachedfile['error'];
						$mybb->input['action'] = $action;
					}
/* + PL:bankpipe + */ else
/* + PL:bankpipe + */ {
/* + PL:bankpipe + */ $args = ['attachedfile' => $attachedfile];
/* + PL:bankpipe + */ $GLOBALS['plugins']->run_hooks('bankpipe_core_add_attachment', $args);
/* + PL:bankpipe + */ }

				}
				else
				{
					$ret['errors'][] = $lang->sprintf($lang->error_uploadempty, htmlspecialchars_uni($FILE['name']));
					$mybb->input['action'] = $action;
				}
			}
		}
	}

	return $ret;
}

Please guide.
Thank you.
It can't go in the same place as it did before because a new elseif block has been added since 1.8.26. You just need to put your code after this:

else if(isset($attachedfile['aid']) && $mybb->get_input('ajax', MyBB::INPUT_INT) == 1)
{
	$ret['success'][] = array($attachedfile['aid'], get_attachment_icon(get_extension($filename)), $filename, get_friendly_size($FILE['size']));
}

Before, the code was just this:

if(!empty($attachedfile['error']))
{
	//
}

you added your code after that, which was fine:

if(!empty($attachedfile['error']))
{
	//
}
else
{
	// your code
}

Now there is an elseif after the if:

if(!empty($attachedfile['error']))
{
	//
}
else if(isset($attachedfile['aid']) && $mybb->get_input('ajax', MyBB::INPUT_INT) == 1)
{
	//
}

So you can't put an else directly after the if, as it then looks like this:

if(!empty($attachedfile['error']))
{
	//
}
else
{
	// your code
}
else if(isset($attachedfile['aid']) && $mybb->get_input('ajax', MyBB::INPUT_INT) == 1)
{
	//
}

This isn't valid PHP so it errors.

You need to put your code after the elseif block, so it looks like this:

if(!empty($attachedfile['error']))
{
	//
}
else if(isset($attachedfile['aid']) && $mybb->get_input('ajax', MyBB::INPUT_INT) == 1)
{
	//
}
else
{
	// your code
}
Thanks a lot Matt and Shade.