Welcome Guest, Not a member yet? Register   Sign In
Uploading files to multiple folders..almost there.
#1

[eluser]generalsalt[/eluser]
I have two fields. One is 'userfile' the other is 'project_photos'. I am trying to upload the files uploaded from 'project_photos' to the projects folder and the 'userfile' to the 'thumbails' folder.

I have gone over this code again and again, it seems like it should work. It doesn't of course.

Code:
function do_upload()
{
    $this->load->library('upload');

    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']    = '0';
    $config['max_width']  = '0';
        $config['max_height']  = '0';

    foreach($_FILES as $key=>$value){    
    
      if($key == 'project_photos')
     {
        $config['upload_path'] = './pics/projects';
    }
    else{
    $config['upload_path'] = './pics/thumbnails';
     }
      $this->upload->initialize($config);    
    }


     if ( ! $this->upload->do_upload())
     {
     $errors['errors'] = $this->upload->display_errors();
     $this->load->view('backend/upload_form', $errors);
     }    
     else
     {    
     $this->load->view('backend/upload_success');
     }    
}

Also, curious about the 'do_upload' function. What calls this function? Is it automatically called when A POST is detected?
#2

[eluser]Colin Williams[/eluser]
Quote:What calls this function?

You call that function.

It looks like you don't have a 'userfile' named file upload field, and/or you have not told CI to use a different field. In your foreach, you should set the file field name along with the upload_path
#3

[eluser]generalsalt[/eluser]
I have two form fields one called name="project_photos[]" and by default CI calls the other one 'userfile'.

Can you expand on that a little? What does setting the 'file field' do, and how do you set it?
#4

[eluser]generalsalt[/eluser]
[quote author="Colin Williams" date="1239791067"]
You call that function.
[/quote]

What I mean is I see in the User Manual it says to do this to set your own field name:

Code:
$field_name = "some_field_name";
$this->upload->do_upload($field_name);

I'm not calling do_upload like that, only setting it as the form action. How do you pass arguments in if you call the 'do_upload' from a form action?
#5

[eluser]generalsalt[/eluser]
Really need some help here..

Right now I have :

Code:
<form action="http://url.com/upload/do_upload" method="post" enctype="multipart/form-data">

How do I specify different fields calling he do_upload functin like this?
#6

[eluser]generalsalt[/eluser]
Code:
if($field == 'project_photos')
{
    $config['upload_path'] = './projects/';
    $this->upload->do_upload();
}
else{
        $config['upload_path'] = './pics/thumbnails/';
    $this->upload->do_upload();
}

This worked..yaaah..me.




Theme © iAndrew 2016 - Forum software by © MyBB