Welcome Guest, Not a member yet? Register   Sign In
forms uploading image and text
#1

[eluser]andieevans[/eluser]
Hi

New to ci and the site.

Working on a website where I want the user to upload an some information which can be text and or an image..

so I have a form with some text inputs and a single file input.

I generated the form using the form helper

echo form_input('myinput')
echo form_submit('submit')

and so on...


trouble is I can see from my code that I am getting the text inputs data posted, but the file input appears to be blank...

I have some code like this to see what is being posted:

Code:
print_r($this->input->post());
  die();

this is handy as I can see every form field and the value being sent.

the problem I have is that even if I select a file, the file input is not listed in the array.... any ideas what could be up?

#2

[eluser]ojcarga[/eluser]
Are you using form_open_multipart() to open <form ..> tag??

Here you can see about "form_open_multipart()"
http://ellislab.com/codeigniter/user-gui...elper.html

Here some help with the file upload
http://ellislab.com/codeigniter/user-gui...ading.html
#3

[eluser]andieevans[/eluser]
hi ojcarga

thanks for the assist, yes i did use the form_open_multipart() to generate the form

I also used form_close()
#4

[eluser]ojcarga[/eluser]
I have worked uploading files just once but maybe this can help.

I used this to create my inputs (VIEW FILE)
Code:
$cfile=array('name'=>'fileup', 'id'=>'fileup', 'value'=>'File');
echo form_upload($cfile);

My Controller
Code:
function upload_psd() {
        if(!ini_get('safe_mode')) {
            set_time_limit(240);
            ini_set('max_execution_time',0);
            ini_set('memory_limit', '32M');
            ini_set('upload_max_filesize', '35M');
            ini_set('post_max_size', '35M');
            ini_set('max_input_time', 900);            
        }
                
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'zip|jpg';
$config['max_size'] = '35840';

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

        if ( ! $this->upload->do_upload("fileup")){
            //$error = array('error' => $this->upload->display_errors());
            //echo '<p>NO SUBIO NI PICHA</p><br />';            
            return false;
        }else{
            //$data = array('upload_data' => $this->upload->data());
            //echo '<p>SI se subio muy bien</p><br />';
            return true;
        }
    }

I had to add the ini_set directives cause my server did not let me uploads anything, maybe you don't need them.
#5

[eluser]andieevans[/eluser]
hi

thanks for the help

I got it to work in the end... I was calling a model method from my controller to upload the file, and as such the reference to the file I wanted to upload was getting 'lost'

I moved the upload code to the controller and it works fine. I am still able to send the form data to the database via the model method, just not the file.

Thanks again.

;o)







Theme © iAndrew 2016 - Forum software by © MyBB