1

I am uploading and re-sizing multiple images, but this code work good for 1 file if i upload 2 or more file it will re-size 1st pic as complete black and all other pics uploaded unchanged.

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'] = '100';
                $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);

                }
            }
        }

where i am missing something, that re-size function is not working accurate.

Farrukh Javed
  • 39
  • 2
  • 7

2 Answers2

0

Below this line

$path=$data['upload_data']['full_path'];

write

echo $path;

then check what is the output?

Arslan Tabassum
  • 900
  • 1
  • 10
  • 25
  • the out put is this while uploading 3 images. C:/xampp/htdocs/up/uploads/galaxy-s3-live-hd-207323-3-s-307x512.jpg C:/xampp/htdocs/up/uploads/iamge21.jpg C:/xampp/htdocs/up/uploads/images1.jpg – Farrukh Javed Mar 03 '15 at 11:38
  • its accurate path for pics but i guess resize function is not used right. – Farrukh Javed Mar 03 '15 at 11:39
0

please try below

function do_upload(){

$this->load->library('upload');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width']  = '1024';
$config['max_height']  = '768';

 foreach($_FILES['userfile'] as $key => $value)
{

    if( ! empty($key['name']))
    {

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

        if ( ! $this->upload->do_upload($key))
        {
            $error['error'] = $this->upload->display_errors();

            $this->load->view('pages/uploadform', $error);
        }    
        else
        {
            $data[$key] = array('upload_data' => $this->upload->data());

            $this->load->view('pages/uploadsuccess', $data[$key]);


        }
     }

}    

}
}