Welcome Guest, Not a member yet? Register   Sign In
Set Max Size in CodeIgniter File Upload
#1

I am trying to a jpeg file which is more than 2mb even after setting maximum size in my php.ini but still the file is not getting uploaded. Please help to find the solution for this problem.

How can I increase the maximum file upload size?


Code:
public function handle_upload($str,$is_required)
    {
     
        $image_validate = $this->config->item('file_validate');

        if (isset($_FILES["file"]) && !empty($_FILES['file']['name']) && $_FILES["file"]["size"] > 0) {

            $file_type         = $_FILES["file"]['type'];
            $file_size         = $_FILES["file"]["size"];
            $file_name         = $_FILES["file"]["name"];
            $allowed_extension = $image_validate['allowed_extension'];
            $ext               = pathinfo($file_name, PATHINFO_EXTENSION);

            $allowed_mime_type = $image_validate['allowed_mime_type'];

            $finfo = finfo_open(FILEINFO_MIME_TYPE);
            $mtype = finfo_file($finfo, $_FILES['file']['tmp_name']);
            finfo_close($finfo);

            if (!in_array($mtype, $allowed_mime_type)) {
                $this->form_validation->set_message('handle_upload', 'File Type Not Allowed');
                return false;
            }

            if (!in_array($ext, $allowed_extension) || !in_array($file_type, $allowed_mime_type)) {
                $this->form_validation->set_message('handle_upload', 'Extension Not Allowed');
                return false;
            }

            if ($file_size > $image_validate['upload_size']) {
                $this->form_validation->set_message('handle_upload', $this->lang->line('file_size_shoud_be_less_than') . number_format($image_validate['upload_size'] / 1048576, 2) . " MB");
                return false;
            }

            return true;
        } else {
          if($is_required==0){
             $this->form_validation->set_message('handle_upload', 'Please choose a file to upload.');
            return false;
          }else{
             return true;
          }
           
        }
       

    }
Reply
#2

(This post was last modified: 04-25-2020, 03:58 PM by php_rocs.)

@EseMiami,

What php.ini settings did you set (and what amount)? Hopefully you set these (memory_limit, upload_max_filesize, post_max_size).
Reply
#3

(04-25-2020, 03:37 PM)php_rocs Wrote: @EseMiami,

What php.ini settings did you set (and what amount)?  Hopefully you set these (memory_limit, upload_max_filesize, post_max_size).
This is what I did ....

In cPanel  I searched for php, then "Select PHP version" under Software.

Software -> Select PHP Version -> Switch to Php Options -> Change Value -> save.


I set my memory_limit to =128M

upload_max_size =128M

post_max_size = 128M
Reply
#4

@EseMiami,

Did you check the values of $_FILES["file"]['type'], $_FILES["file"]["size"], $_FILES["file"]["name"]? What was it? Also, if you are getting an error what is the error message?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB