I am trying to upload image with a check of max 2MB size. I am trying an image of 6.44MB to check the test case. If image size if more than 2MB, the uploader should get relevant message.
My Form is:

```
<?php echo form_open_multipart('Addthepic');?>
<table>
  <tr>
     <td><input type="file" name="image">(Dimension should be 370*234)</td>
     <td><input type="text" name="alt_text" placeholder="Alternate Text"></td>
     <td><input type="text" name="title" placeholder="Title"></td>
     <td><input type="text" name="caption" placeholder="Caption"></td>
     <td><input type="submit" name="submit" class="btn btn-success" value="Add Now"></td>
  </tr>
</table>
<?php echo form_close();?>

```

The code in my Model is:

```
if(!empty($_FILES['image']['name']) && $_FILES['image']['size']>2097152)
{
    return "<div class='alert alert-danger'>Max 2MB file is allowed for image.</div>";
}
else
{
    var_dump($_FILES['image']);
    $msg.="<div class='alert alert-success'>".$_FILES['image']['error']."</div>";
    $config1=array(
        'upload_path'=>$_SERVER['DOCUMENT_ROOT']."/assets/uploads/eimg/",
        'allowed_types'=>"gif|jpg|png|jpeg|pdf|JPG|JPEG",
        'overwrite'  => TRUE,
        'file_name' =>$filename
    );
    $this->load->library('upload',$config1);
    $this->upload->overwrite = true;
    if($this->upload->do_upload('image'))
    {
        $image_data =   $this->upload->data();
        $configer1 =  array(
          'image_library'   => 'gd2',
          'source_image'    =>  $image_data['full_path'],
          'maintain_ratio'  =>  FALSE,
          'width'           =>  370,
          'height'          =>  234,
          'overwrite'       =>  TRUE,
          'file_name'       =>  $filename
        );
        $this->image_lib->clear();
        $this->image_lib->initialize($configer1);
        $this->image_lib->resize();
        $this->db->where('sno',$sno);
        $this->db->update('events',array('image'=>$filename));
        if($this->db->affected_rows()>0)
            $msg.= "<div class='alert alert-success'>Image has been uploaded successfully</div>";
    }
}

```

> 
> Permissions of eimg directory is 0777 on server
> 
> 
> 

var\_dump gives the following output:

```
array(5) { ["name"]=> string(12) "Imgname.JPG" ["type"]=> string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(1) ["size"]=> int(0) }

```

$\_FILES['image']['error'] gives

```
1

```

$\_FILES['image']['size'] gives

```
0

```

$\_FILES['image']['name'] shows the file name correctly