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
}
}
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