Welcome Guest, Not a member yet? Register   Sign In
Problem when upload file though jquery
#1

[eluser]Ricola[/eluser]
i have problem when i submit my jquery form to store my data but everything done fine !

except my file field , and i got a error message " You did not select a file to upload. ".

I actually tested this code with a simple html and without using jquery everything work fine also

including my file can be stored .

I'm using Codeigniter 2.0

This is my controller

Code:
public function create()
    {

        $config['upload_path'] = './public/images';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload('pPicture'))
        {
            $error = array('error' => $this->upload->display_errors());

            echo $error;
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
            echo $data;

        }

    }


and this is a part of my view file
Code:
<div id="create">
        &lt;form method="post" enctype="multipart/form-data" /&gt;
           <p>
               <label for="name">Name:</label>
               &lt;input type="text" id="pName" name="pName" /&gt;
           </p>

           <p>
           <label for="productpicture">Picture:</label>
           &lt;input type="file" name="pPicture" id="pPicture" size="200" /&gt;
           </p>
          
           <p>
               <label>&nbsp;</label>
               &lt;input type="submit" name="createSubmit" value="Submit" /&gt;
           </p>
        &lt;/form&gt;
    </div>

and this is a part of my jquery file
Code:
submitHandler: function( form ) {
            $( '#ajaxLoadAni' ).fadeIn( 'slow' );
            
            $.ajax({
                url: 'administrator/product/create',
                type: 'POST',
                data: $( form ).serialize(),
...


As i said every field can be stored ! except file field

Hope you guys could give me any suggestion because i already stuck in this part for 3 days.

Thanks in advanced
#2

[eluser]Ricola[/eluser]
any suggest?
#3

[eluser]sorenchr[/eluser]
Maybe you are not posting your entire controller, but it seems like you never grab the POST-data from your form? Something like:

Code:
$pPicture = $this->input->post('pPicture');

Before your if ( ! $this->upload->do_upload('pPicture')) statement
#4

[eluser]Ricola[/eluser]
i have ever tried it , but nothing happen

actually i bring a part of code above from codeigniter user guide

and i have already used without jquery and it works fine.

but i dont know extactly why i can't use upload code above with jquery

and the point is why only the file field can't upload the picture but another textfield in the same view still work normally.




Theme © iAndrew 2016 - Forum software by © MyBB