PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 10, 2022

[FIXED] Unable to load file class in Code igniter

 January 10, 2022     codeigniter, file, model-view-controller     No comments   

Issue

im new to php. Recently im doing a page where you can create a miniblog and uplolad a file. But when i click the submit button, theres error that said "Unable to load File class" can anyone help me to see where i do wrong? thankyou in advance.

this is my form (view) code where user submit their files

<form enctype="multipart/form-data" action = "<?= base_url().'admin/blog/addblog_post' ?>" method="post">

  <div class="form-group">
    <input type="file" class="form-control" name="file" placeholder="Add a file">
  </div>
  <br>

  <button type="submit" class="btn btn-primary">Add mini blog</button>
  </form>

This one is from the controller where the addblog function is located

function addblog_post()
    {

        print_r($_POST);
        print_r($_FILES);

        if($_FILES)
        {
            //Image can be uploaded
             $config['upload_path']       = './assets/uploads/blogs';
             $config['allowed_types']    = 'gif|jpg|png';
               

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

                if ( ! $this->upload->do_upload('file'))
                {
                        $error = array('error' => $this->upload->display_errors());

                        die("Error");

                        // $this->load->view('upload_form', $error);
                }
                else
                {
                        $data = array('upload_data' => $this->upload->data());
                        echo "<pre>";
                        print_r($data);

                        // $this->load->view('upload_success', $data);
                }
        }
        else
        {
            //Image cannot passed

        }

    }

Solution

There's no library with the name "file" in CI

if you want to upload a file you can make use of File upload library

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

for more info go through Libraries list and File Upload Library



Answered By - Maroof
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing