Welcome Guest, Not a member yet? Register   Sign In
having a problem setting session data?
#1

[eluser]moonshine[/eluser]
hi
I've been working on this for too long now and haven't been sleeping well lately so plz excuse if i'm missing something obvious.

i'm having a problem with an upload form and the relating method in the upload_model to store to the session data..

how the page is meant to work is that a user uploads it gets displayed and then the user the user can then upload another image or cancel, until user presses the <input type="submit" value="CONFIRM UPLOAD"...(not shown) then all the images are processed and stored in the database
but they can only upload a set number of images per clue and there is a set number of clues..

i've inherited the code so that makes it a bit tricker too..

the problem is that when the page is reloaded after the upload image button is pressed
only the last image is being displayed (the last in terms of looping through the multidimensional array.)

the array seems to be being re-stored each time aswell<- don't know if i'm describing this well, but the print_r() output at the bottom should help.

in upload model
Code:
if ($result['success']) {
    // retrieve file upload data from user's session
    $file = $this-&gt;session->userdata('file');
    
    // store details of file upload in user's session
    $file[$clue_num][$image_num] = array('filename' => $result['data']['file_name'], 'caption' => $this->input->post("caption_$image_num"."_$clue_num"));
    $data_for_session = array('file' => $file);
    $this->session->set_userdata($data_for_session);

and the view

Code:
if(!empty($user_session_file_data))
    {
        foreach ($user_session_file_data as $stored_clue_num => $subArray)
        {
            foreach ($subArray as $stored_image_num=>$value)
            {
                if($stored_clue_num==$clue_num && $stored_image_num==$image_num){$image_uploaded = TRUE;}
                else{$image_uploaded = FALSE;}
            }
        }
    }
    else{$image_uploaded = FALSE;}
    ?&gt;
    &lt;input type="file" style="margin-bottom: 1; margin-left: 0px; width: 250px;" name="&lt;?=$file_field?&gt;" /&gt;
    FORM FIELD NAME=&lt;?=$file_field?&gt;---<BR>
    &lt;input type="submit" class="login_submit" value="UPLOAD NOW" name="&lt;?=$upload_field?&gt;" style="width: 130px;" /&gt;
    <br>&lt;?="$upload_field"?&gt; --test<BR>
    <br clear="all" />
    
    <span style='font-size: 12px; margin: 0px;'>&lt;?=$this->lang->line("upload_upload_add_caption");?&gt;</span><br />
    &lt;input type="text" style="margin-bottom:1; margin-left:0px; width:200px;" value="&lt;?= ($image_uploaded) ? $user_session_file_data[$clue_num][$image_num]['ca] : ''?&gt;" name="&lt;?=$cafield?&gt;"/&gt;

    <br class="cleardouble"/>
</div>
&lt;? if ($image_uploaded) { ?&gt;
    <div style="float: left; border: 1px solid #cccccc; margin-left: 20px;">
        &lt;?//test print_r($user_session_file_data)?&gt;
        <img src="/photos/tmp/&lt;?=$this->Photos_model->photo_name($user_session_file_data[$clue_num][$image_num]['filename'], 'thumb')?&gt;" width="150" />
    </div>
&lt;? } ?&gt;


and this is the print_r($file); after 3 uploads
Code:
Array ( [01] => Array ( [1] => Array ( [filename] => 36511.jpg [caption] => bathalona ) [2] => Array ( [filename] => 3664.jpg [caption] => bbq cat ) [3] => Array ( [filename] => 2006_0412Image00493.JPG [caption] => alfie sleep ) ) ) Array ( [01] => Array ( [1] => Array ( [filename] => 36511.jpg [caption] => bathalona ) [2] => Array ( [filename] => 3664.jpg [caption] => bbq cat ) [3] => Array ( [filename] => 2006_0412Image00493.JPG [caption] => alfie sleep ) ) ) Array ( [01] => Array ( [1] => Array ( [filename] => 36511.jpg [caption] => bathalona ) [2] => Array ( [filename] => 3664.jpg [caption] => bbq cat ) [3] => Array ( [filename] => 2006_0412Image00493.JPG [caption] => alfie sleep ) ) )

there are 3 arrays all containing the same data
any help greatly apreciated
#2

[eluser]moonshine[/eluser]
i found my problem
(it's obvious i haven't been sleeping much... i was clobbering the test? derrr.

any how i don't like my solution but it works, any pointers on how to make this DRYer or about how to move some of this code to the controller or model?
Code:
if(!empty($user_session_file_data))
    {
        foreach ($user_session_file_data as $stored_clue_num => $subArray)
        {echo '<BR><BR>uped cn:'.$stored_clue_num.'<BR>';
            foreach ($subArray as $stored_image_num=>$value)
            {echo '&nbsp;&nbsp;&nbsp;&nbsp;uped in:'.$stored_image_num.'<BR>';
                if($stored_clue_num==$clue_num && $stored_image_num==$image_num){
                    $image_uploaded = TRUE;?&gt;
                    &lt;input type="text" style="margin-bottom:10px; margin-left:0px; width:200px;" value="&lt;?= ($image_uploaded) ? $user_session_file_data[$clue_num][$image_num]['caption'] : ''?&gt;" name="&lt;?=$caption_field?&gt;"/&gt;
                    &lt;?
                }
                else{$image_uploaded = FALSE;?&gt;
                &lt;input type="text" style="margin-bottom:10px; margin-left:0px; width:200px;" value="&lt;?= ($image_uploaded) ? $user_session_file_data[$clue_num][$image_num]['caption'] : ''?&gt;" name="&lt;?=$caption_field?&gt;"/&gt;
                &lt;?}
            }
        }
    }
    else{$image_uploaded = FALSE;?&gt;
    &lt;input type="text" style="margin-bottom:10px; margin-left:0px; width:200px;" value="&lt;?= ($image_uploaded) ? $user_session_file_data[$clue_num][$image_num]['caption'] : ''?&gt;" name="&lt;?=$caption_field?&gt;"/&gt;
    &lt;?}?&gt;

    <br class="cleardouble"/>
</div>
&lt;?
if(!empty($user_session_file_data))
{
    foreach ($user_session_file_data as $stored_clue_num => $subArray)
    {echo '<BR><BR>uped cn:'.$stored_clue_num.'<BR>';
        foreach ($subArray as $stored_image_num=>$value)
        {echo '&nbsp;&nbsp;&nbsp;&nbsp;uped in:'.$stored_image_num.'<BR>';
            if($stored_clue_num==$clue_num && $stored_image_num==$image_num){
                $image_uploaded = TRUE;
                ?&gt;
                    <div style="float: left; border: 1px solid #cccccc; margin-left: 20px;">
                        &lt;? print_r($user_session_file_data)?&gt;
                        <img src="/photos/tmp/&lt;?=$this->Photos_model->photo_name($user_session_file_data[$clue_num][$image_num]['filename'], 'thumb')?&gt;" width="150" />
                    </div>
                &lt;?
            }
        }
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB