Мне нужно вставить значение файла типа ввода в базу данных MySQL.Я отправляю файл после проверки формы.Но при вставке значение файла отображается как NULL, и отображается номер ошибки: 1048.
Мне нужно вставить имя изображения в базу данных вместе с другими полями.Но проверка типа ввода File не работает
мой код
контроллер
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Book extends CI_Controller {
public function index()
{
$this->load->view('admin/add_book');
}
public function addbook()
{
$this->load->view('admin/add_book');
}
public function form_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules("book_name","Book Name",'required');
$this->form_validation->set_rules("book_author","Author",'required');
$this->form_validation->set_rules("book_pub","Publications",'required');
$this->form_validation->set_rules("book_genre","Genre",'required|alpha');
$this->form_validation->set_rules("pub_year","Year",'required');
if (empty($_FILES['book_cover']['name']))
{
$this->form_validation->set_rules("book_cover","Document",'required');
}
if($this->form_validation->run())
{
$this->load->model("book_model");
$data=array(
"book_name"=>$this->input->post("book_name"),
"book_author"=>$this->input->post("book_author"),
"book_publication"=>$this->input->post("book_pub"),
"book_genre"=>$this->input->post("book_genre"),
"book_year"=>$this->input->post("pub_year"),
"book_cover"=>$this->input->post("book_cover")
);
$this->book_model->insert_data($data);
redirect(base_url()."admin/book/inserted");
echo "Success";
}
else
{
$this->index();
//echo "Fail";
}
}
public function inserted()
{
$this->addbook();
}
}
?>
модель
<?php
class Book_model extends CI_Model
{
function insert_data($data)
{
$this->db->insert("books",$data);
}
}
?>
просмотр
<form action="<?php echo base_url()?>admin/book/form_validation" method="post" class="form-horizontal form-bordered" enctype="multipart/form-data" >
<?php
if($this->uri->segment(3) == "inserted")
{
echo '<p class="text-success" style="text-align:center;">Data Inserted</p>';
}
?>
<div class="form-group">
<label class="col-md-3 control-label" for="example-hf-email">Book Name</label>
<div class="col-md-9">
<input type="text" name="book_name" class="form-control" placeholder="Enter Name..">
<span class="text-danger"><?php echo form_error("book_name");?></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="example-hf-password">Author Name</label>
<div class="col-md-9">
<input type="text" name="book_author" class="form-control" placeholder="Enter Author..">
<span class="text-danger"><?php echo form_error("book_author");?></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="example-hf-password">Publications</label>
<div class="col-md-9">
<input type="text" name="book_pub" class="form-control" placeholder="Enter Publication..">
<span class="text-danger"><?php echo form_error("book_pub");?></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="example-hf-password">Genre</label>
<div class="col-md-9">
<input type="text" name="book_genre" class="form-control" placeholder="Enter Genre..">
<span class="text-danger"><?php echo form_error("book_genre");?></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="example-hf-password">Year</label>
<div class="col-md-9">
<input type="text" name="pub_year" class="form-control" placeholder="Enter Salary..">
<span class="text-danger"><?php echo form_error("pub_year");?></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="example-hf-password">Book Cover Image</label>
<div class="col-md-9">
<input type="file" name="book_cover" class="form-control" placeholder="upload book cover..">
<span class="text-danger"><?php echo form_error("book_cover");?></span>
</div>
</div>
<div class="form-group form-actions">
<div class="col-md-9 col-md-offset-3">
<button type="submit" name="save" class="btn btn-sm btn-primary"><i class="fa fa-user"></i> Save</button>
<button type="reset" class="btn btn-sm btn-warning"><i class="fa fa-repeat"></i> Reset</button>
</div>
</div>
</form>
Я не совсем понимаю проблему.Заранее спасибо