Welcome Guest, Not a member yet? Register   Sign In
How to upload image in different folder
#1

[eluser]MASS MASS[/eluser]
My code is as shown below


for($i = 1; $i<3 ; $i++)
{
if($i == 1)
{
$config['upload_path'] = './uploads/galleries/one folder'.;
$config['max_size'] = '1000';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);

}
else
{
$config['upload_path'] = './uploads/galleries/two folder'.;
$config['max_size'] = '1000';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
}


if (!$this->upload->do_upload($userfile))
{
return $this->upload->display_errors();
}

}

Problems of code........
--------------------------

Uploading is not a problem.........

Storing in folder is problem ...........it is always storing
........in './uploads/galleries/one folder'.; (one folder)

why its storing always in one folder;
#2

[eluser]xwero[/eluser]
I'm just guessing here but i think it has to do with the loading of the library. try this
Code:
$config[’max_size’] = ‘1000’;
$config[’allowed_types’] = ‘gif|jpg|png’;
for($i = 1; $i<3 ; $i++)
{
if($i == 1)
{
$config[’upload_path’] = ‘./uploads/galleries/one folder’;
}
else
{
$config[’upload_path’] = ‘./uploads/galleries/two folder’;
}

$this->load->library(’upload’, $config);
if (!$this->upload->do_upload($userfile))
{
return $this->upload->display_errors();
}

}
I've also places some of the config options outside the loop because they stay the same.
#3

[eluser]MASS MASS[/eluser]
I tried this ...........its not working.....i think this is same as mine..........
#4

[eluser]xwero[/eluser]
Where does the $userfile in the do_upload method comes from? If you have a field named userfile you don't have to add this.

instead of loading the library in your loop you could do
Code:
$this->load->library(’upload’);
$config[’max_size’] = ‘1000’;
$config[’allowed_types’] = ‘gif|jpg|png’;
for($i = 1; $i<3 ; $i++)
{
if($i == 1)
{
$config[’upload_path’] = ‘./uploads/galleries/one folder’;
}
else
{
$config[’upload_path’] = ‘./uploads/galleries/two folder’;
}

$this->upload->initialize($config);
if (!$this->upload->do_upload($userfile))
{
return $this->upload->display_errors();
}

}
#5

[eluser]MASS MASS[/eluser]
Same thing happening..............what to do.........userfile is not a problem (i am getting properly)..

only storing is problem....
#6

[eluser]xwero[/eluser]
You could check the config array by printing it out during the loop an see if the config array changes.
#7

[eluser]MASS MASS[/eluser]
Yours Second reply is working correctly..........

that is :

$this->upload->initialize($config);

This is correct way to do this.............that time i am unset that variable....that is the problem..

i checked after your third reply ......print_r($config)...

Now its working fine ........

You save my half day....

Thank you so much : xwero.......




Theme © iAndrew 2016 - Forum software by © MyBB