Welcome Guest, Not a member yet? Register   Sign In
fileupload and multipart/form-data problems
#1

[eluser]Unknown[/eluser]
Hi, I'm new with CI. Get on with MCV model ...

I'm making procedural file upload for a long time now I try with CI and face up to a problem with the multipart/form-data encryption form.

A form to add a document to a DB work fine without the encryption form data (with no file upload) when I add file uploading to my form with encryption form data the form has been refresh keeping all post element except my file input that's vanished.

there my code .. if some CI guru can help me ...

the controller
Code:
function addDoc ()
    {
        $this->load->library('validation');
        
        $ua_data['listAllCats'] = $this->docs_model->listUG('cluster');
        $ua_data['listAllGroups'] = $this->docs_model->listUG('docs');
        //$ua_data['listAllCats'] = 'data';
        $rules['pid'] = "required|xss_clean";
        $rules['catid'] = "required|numeric|xss_clean";
        $rules['title'] = "required|max_length[100]";
        $rules['auteur'] = "required|max_length[100]";
        $rules['date'] = "required";
        $rules['status'] = "required";
        $rules['userfile'] = "required";
        $rules['url'] = "required";
        $this->validation->set_rules($rules);
        
        $fields['pid'] = $this->lang->line('dc_pid');
        $fields['catid'] = $this->lang->line('dc_catid');
        $fields['title'] = $this->lang->line('dc_title');
        $fields['auteur'] = $this->lang->line('dc_auteur');
        $fields['date'] = $this->lang->line('dc_date');
        $fields['status'] = $this->lang->line('dc_status');
        $fields['userfile'] = $this->lang->line('dc_src');
        $fields['url'] = $this->lang->line('dc_url');
        $this->validation->set_fields($fields);
        $this->validation->set_error_delimiters('<span class="error">', '</span>');


        if ($this->validation->run() == TRUE) {
            $pid = $this->input->post('pid', TRUE);
            $catid = $this->input->post('catid', TRUE);
            $title = $this->input->post('title', TRUE);
            $auteur    = $this->input->post('auteur', TRUE);
            $date  = $this->input->post('date', TRUE);
            $stat    = $this->input->post('status', TRUE);
            $url    = $this->input->post('url', TRUE);
            $file    = $this->input->post('userfile', TRUE);
    
            // validation and upload file from the form
        $this->load->library('upload');
        $config['upload_path'] = './uploads/';
        $this->upload->initialize($config);
        $uploaded = $this->upload->do_upload($file ,true);
            
        $status = $this->docs_model->addDocs($pid, $catid, $title, $auteur, $date, $stat, $url, $file);
            
            
            if ($status == 0) {
                $ua_data['msg'] = $this->lang->line('dc_missing');
            } elseif ($status == 1) {
            
                // checking for errors + building error string
                if (!$this->upload->do_upload($file))
                {
                    $this->session->set_flashdata('msg',$this->upload->display_errors(). $this->lang->line('dc_user_added') );
                } else {
                
                    $this->session->set_flashdata('msg',$this->upload->data(). $this->lang->line('dc_user_added') );
                }
                    //$this->session->set_flashdata('msg', $this->lang->line('dc_user_added'));
                    redirect('admin/docs', 'location');    
                    
            } else {
                $ua_data['msg'] = $this->lang->line('dc_user_exists');
            }
        }
        $ua_data['mode'] = 'add';
        $data['nav'] = 'addcontent';
        $ua_data['form_title'] = $data['title'] = $this->lang->line('dc_adddoc');
        
        $data['extraHeadContent'] = '&lt;link type="text/css" rel="stylesheet" href="' . base_url().
            '/css/userauth.css" /&gt;
        
        $data['content'] = $this->load->view('docs/docs_form', $ua_data, TRUE);

        // Display in Template
        $this->load->view('template', $data);
    }
and there's the view

Code:
&lt;form action="&lt;?= site_url('admin/docs/addDoc');?&gt;" method="post" enctype="multipart/form-data" name="addDocs" id="addDocs"&gt;
< .... >
<label for="userfile">&lt;?= $this->lang->line('dc_src');?&gt;</label>
        </td><td>
            &lt;input name="userfile" type="file" id="userfile" size="30" value="&lt;?=$this-&gt;validation->userfile;?&gt;" /> &lt;?=$this->validation->userfile_error; ?&gt;
             &lt;input type="hidden" name="post_max_size" value="999999999999"&gt;
             &lt;input type="hidden" name="MAX_FILE_SIZE" value="999999999999"&gt;
        </td></tr>
        <tr><td>
        </td><td>&lt;input type="submit" value="&lt;?= $this-&gt;lang->line('dc_adddoc');?&gt;" />

NEW THINGS :
I've added print_r($_FILE) and I see all my $FILE array with the file information...
Why my controller back to the form ???




Theme © iAndrew 2016 - Forum software by © MyBB