Home > Software design >  setting width and height of image in codeigniter php not working
setting width and height of image in codeigniter php not working

Time:06-06

i have a codeigniter website where user can upload multiple images, i want all the images to be of the same size, i have done the following code in controller:

if (isset($_POST['addblog'])) {
    $this->load->library('upload');
    $image = array();
    $ImageCount = count($_FILES['image_name']['name']);

    for ($i = 0; $i < $ImageCount; $i  ) {
        $_FILES['file']['name'] = $_FILES['image_name']['name'][$i];
        $_FILES['file']['type'] = $_FILES['image_name']['type'][$i];
        $_FILES['file']['tmp_name'] = $_FILES['image_name']['tmp_name'][$i];
        $_FILES['file']['error'] = $_FILES['image_name']['error'][$i];
        $_FILES['file']['size'] = $_FILES['image_name']['size'][$i];

        $uploadPath = './uploads/blog/';
        $config['upload_path'] = $uploadPath;
        $config['allowed_types'] = 'jpg|jpeg|png|gif';
        $config['width'] = 200;
        $config['height'] = 250;

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

        if ($this->upload->do_upload('file')) {

            $imageData = $this->upload->data();

            $uploadImgData[] = $imageData['file_name'];
        }
    }
    $blogimage = $uploadImgData;
}

as u can see i have set the height and width in config, the images are still uploaded in ther original size, can anyone please tell me what is wrong in here, thanks in advance

CodePudding user response:

You has just made a little mistake in your config :

$config['max_width'] = 200; 
$config['max_height'] = 250; 

Sadly "min_width" and "min_height" seems doesn't exist yet

  • Related