1

I am able to upload my images ok, I am able to create thumbnails ok, but only the first thumbnail is being uploaded. I checked the error code for the resize function and they all say 'true' (Success). However, if I upload 4 files, only the first is being uploaded to the thumbnail folder. Here is my code:

function _upload_them_images($_FILES, $last_insert_id)
{
    $error = '';
    // for($i=0; $i<count($_FILES); $i++)
    for($i=0; $i<count($_FILES['imagefile']['name']); $i++)
    {

        $_FILES['userfile']['name']         = $_FILES['imagefile']['name'][$i];
        $_FILES['userfile']['type']         = $_FILES['imagefile']['type'][$i];
        $_FILES['userfile']['tmp_name']     = $_FILES['imagefile']['tmp_name'][$i];
        $_FILES['userfile']['error']    = $_FILES['imagefile']['error'][$i];
        $_FILES['userfile']['size']     = $_FILES['imagefile']['size'][$i];

        $config['file_name']     = $last_insert_id.'_'.time().rand(1000,9999).$i;
        $config['upload_path']   = './images/vehicles/';
        $config['allowed_types'] = 'jpg|jpeg|gif|png';
        $config['max_size']      = '1000';
        $config['overwrite']     = FALSE;

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

        if($this->upload->do_upload())
        {
            $upload_result = $this->upload->data();             
            $rc = $this->_image_name_into_database(
                $last_insert_id,
                $upload_result['file_name']);               
            $image_config = array(
                'source_image'      =>$upload_result['full_path'],
                'new_image'             => './images/vehicles/thumbs/', 
                'create_thumb'      => TRUE,
                'maintain_ratio'    => TRUE,
                'width'                     => 75, 
                'height'                    => 50
            );

            $this->load->library('image_lib', $image_config);
            $resize_rc = $this->image_lib->resize();            
            $error += 0;            
        }
        else
        {    
            //if the image was not uploaded successfully, try resizing  
            $error += 1;
        }
    }
    if($error > 0)
    { 
        return FALSE; 
    }
    else
    { 
        return TRUE; 
    }     
}  
4

1 回答 1

2

您的图像库参数不会在循环中更新。当您调用 时$this->load->....,将忽略重复项。您应该使用以下方法重新初始化图像库:

$this->image_lib->clear();
$this->image_lib->initialize($image_config);  

每次之前->resize()

于 2012-05-09T00:02:14.257 回答