[eluser]geogis[/eluser]
Hello,
I am getting frustrated with that code...
I am trying to uplaod 2 files in one go. They have to be resized as well... Here is what I have.
Upload and resize function:
Code:
function do_upload($filename,$field)
{
$config = array();
$config['upload_path'] = './system/images_adds/';
$config['allowed_types'] = 'jpg|gif|png';
$config['max_size'] = '5000';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload($field))
{
return array('status'=>0, 'error'=>$this->upload->display_errors());
}
else
{
$this->file = $this->upload->data();
$config = array();
$config = array(
'image_library' => 'gd2',
'source_image' => './system/images_adds/'.$this->file['file_name'],
'maintain_ratio' => TRUE,
'width' => 150,
'height' => 150,
'new_image' => './system/images_adds/test/'.$filename.$this->file['file_ext']
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear();
$info = $this->upload->data();
return array('status'=>1, 'info'=>$info);
}
}
The code I am using when processing the form:
Code:
$data["file"] = $_FILES["userfile"]['name'];
if (!$data["file"] == "")
{
$filename = $category."_".$town;
$result = $this->do_upload($filename,'userfile');
if ($result['status']=="1")
{
$data["ok"]=1;
}
else
{
$data["ok"]=0;
}
}
else
{
}
$data["file2"] = $_FILES["userfile2"]['name'];
if (!$data["file2"] == "")
{
$filename = $category."_".$town."b";
$result = $this->do_upload($filename,'userfile2');
if ($result['status']=="1")
{
$data["ok"]=1;
}
else
{
$data["ok"]=0;
}
}
else
{
}
$category and $town are given before that code.
The problem? It uploads both files to './system/images_adds/' directory and always resize and copy the first file to new directory './system/images_adds/test' but never the second one. I need to have both of them resized in 'test' folder.
What am I doing wrong?
Thanks for help!