0

As i am beginner in PHP so i am facing difficulty even after the help of tutorials. My code upload the multiple pictures but it re-size only 1st Picture and rest of the pictures remain same as they are uploaded. I have tried unset and clear() but problem is same. I will really appreciate if some one will help me to resolve this problem.

function do_upload()
    {    
        $files = $_FILES;    
        $cpt = count($_FILES['userfile']['name']);

        for($i=0; $i<$cpt; $i++)
        {

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

            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']    = '2000';
            $config['max_width']   = '1024';
            $config['max_height']  = '768';

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

            if ( ! $this->upload->do_upload())
            {
                $error = array('error' => $this->upload->display_errors());    
                $this->load->view('upload_form', $error);
            }
            else
            {
                $data = array('upload_data' => $this->upload->data());    
                $path=$data['upload_data']['full_path'];
                $q['name']=$data['upload_data']['file_name'];

                 $configi['image_library'] = 'gd2';
                 $configi['source_image']   = $path;
                 $configi['maintain_ratio'] = TRUE;
                 $configi['width']  = 75;
                 $configi['height'] = 50;

                $this->load->library('image_lib', $configi);    
                $this->image_lib->resize();

                $this -> load -> view('upload_success', $q);
                unset($configi);
                $this->load->library('image_lib');
                $this->image_lib->clear(); }}}

1 Answer 1

1

on last 6th line i have used

$this->load->library('image_lib', $configi);

But when we load a library in loop with $configi it make instant when loop execute 1st time. to use new values on every increment of loop we should perform them separately like:

$this->load->library('image_lib');
$this->image_lib->initialize($configi);

and using this way $configi take new values at every increment in loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.