PHP quirk

Since Opentools.de has now gone away I've created this forum to house FAQs and support for this mod in phpBB2.

Moderator: Experts

Locked
Brf
Expert
Posts: 3
Joined: Fri Oct 27, 2006 8:13 pm

PHP quirk

Post by Brf »

I have seen this happen in a few places in my own coding... Is this a bug in newer versions of PHP or something? I have seen some functions unexpectedly return an array inside a [0] of another array, so instead of accessing $var[$i], you actually have to access $var[0][$i].
Vikul wrote:Hi David and BRF,
I really need ur help man .. I have installed the latest version of this mod. I am getting some strange errors . On debugging i found some issues , need ur comments on these . In posting_attachments ...

________________________________________
// Get those attach_ids allowed for lists from the attachments table...
$allowed_attach_ids = array();
if ($post_id)
{
$sql = 'SELECT attach_id
FROM ' . ATTACHMENTS_TABLE . '
WHERE ' . $sql_id . ' = ' . $post_id;
$result = $db->sql_query($sql);

if (!$result)
{
message_die(GENERAL_ERROR, 'Unable to get attachment information.', '', __LINE__, __FILE__, $sql);
}

while ($_row = $db->sql_fetchrow($result))
{
$allowed_attach_ids[] = $_row['attach_id'];
}
$db->sql_freeresult($result);
}

// Check the submitted variables - do not allow wrong values
$actual_id_list = get_var('attach_id_list', array(0));
$actual_list = get_var('attachment_list', array(''));

for ($i = 0; $i < sizeof($actual_list); $i++)
{
if ($actual_id_list[$i] != 0)
{
if (!in_array($actual_id_list[$i], $allowed_attach_ids))
{
message_die(CRITICAL_ERROR, 'You tried to change an attachment you do not have access to', '');
}
}
else
{
// Really new attachment? If so, the filename should be unique...
if (physical_filename_already_stored($actual_list[$i]))
{
message_die(CRITICAL_ERROR, 'You tried to change an attachment you do not have access to', '');
}
}
}




----------------------------

$actual_id_list = get_var('attach_id_list', array(0));
this returns a multidimensional array ... which I belive is not expected here .. all thru the code a one dimensional array is expected by the code.

Reasons why I suspect this :

I upload an attachment --> Success
I go back to the topic and try editing the post ( same user ) and upload a new attachment or delete an existing one , I get a critical error .
(CRITICAL_ERROR, 'You tried to change an attachment you do not have access to',
. On debugging I found that this check was failing

if (!in_array($actual_id_list[$i], $allowed_attach_ids))

If i change this code to
for ($j = 0; $j < sizeof($actual_id_list[$i]); $i++)
if (!in_array($actual_id_list[$i][$j], $allowed_attach_ids)) ..

it works

But this is not the end it starts failing at the next place where a single dimensional array was assumed.

I am not an expert so was wondering if there is some misunderstanding on my part ... I have revisited all the changes that need to be done and can confirm that all have been done as per the install instructions.

One Place where i suspect the issue to be is the attach_mod/includes/function_attach -> get_var function .
I know that this mod has been there for so long and such an error would have been long caught. But I am getting these errors which no one else seem to be getting .. Any help from u guys will be highly appreciated.
I have no signature
Locked