не могу добавить / обновить новости с изображением в codeigniter

контроллер

<?php
class Breaking extends MY_Controller
{

function __construct()
{
parent::__construct();

$this->load->model('breaking_model');
}
public function create_breaking_news()
{
$this->securePage();

if ($this->input->post('submit')) {
$this->form_validation->set_rules('title', ' Breaking News Title', 'required');

$this->form_validation->set_rules('details', ' Breaking News Details', 'required');if ($this->form_validation->run()) {

$added_on = time();// if image is uploaded
if (isset($_FILES['userfile']['name']) && $_FILES['userfile']['size']>0) {
$config['upload_path'] = $this->config->item('upload_path');
$config['allowed_types'] = $this->config->item('allowed_types');
$config['max_size'] = $this->config->item('max_size');
$config['max_width'] = $this->config->item('max_width');
$config['max_height'] = $this->config->item('max_height');
$config['encrypt_name'] = $this->config->item('encrypt_name');

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

if ($this->upload->do_upload()) {
$image = $this->upload->data();

$this->breaking_model->add_news($image['file_name'], $added_on);
$this->session->set_flashdata('msg', '<button class="btn btn-success" style="width:100%;">The Breaking News has been added successfully.</button>');
redirect('breaking/manage-breaking-news');
} else {
$this->session->set_flashdata('msg', $this->upload->display_errors());
redirect('breaking/create-breaking-news');
}

} else {
// if image is not uploaded
$this->breaking_model->add_news(null, $added_on);
$this->session->set_flashdata('msg', '<button class="btn btn-success" style="width:100%;">The About Breaking News been added successfully.</button>');
redirect('breaking/manage-breaking-news');
}
}
}

$data['news_title'] = 'Add Breaking news | Kanchan news.com';
$data['Keywords'] = '';
$data['url'] = '';
$data['content'] = $this->load->view('breaking/create', $data, true);
$this->load->view('kanchan', $data);
}
}

мои модели

function add_news($image, $added_on) {

$this->db->set('title', $this->input->post('title'));

$this->db->set('details', $this->input->post('details'));

$this->db->set('video', $this->input->post('video'));

$this->db->set('images', $image);

$this->db->set('added_on', $added_on);

$this->db->insert('breaking_news');
}

и мой взгляд

<div class="container">
<ol class="breadcrumb">
<li class="active"><?php echo $this->session->userdata('full_name');?></li>
<li class="active">Breaking News</li>
<li class="active">Add Breaking News</li>
</ol>
<?php echo $this->session->set_flashdata('msg');?>

<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="title"> Enetr Breaking News Title :</label>
<hr>
<input type="text" name="title" class="form-control" value="<?php echo set_value('title');?>">
<?php echo form_error('title');?>
</div>
<div class="row">
<div class="col-md-6">

<div class="form-group">
<label for="title"> Enetr Breaking News Images :</label>
<hr>
<input type="file" name="userfile">
<?php echo form_error('userfile');?>
</div>

</div>

<div class="col-md-6">

<div class="form-group">
<label for="title"> Enetr Breaking News Video Url( not required) :</label>
<hr>
<input type="video" name="video" class="form-control" value="<?php echo set_value('video');?>">
<?php echo form_error('video');?>
</div>
</div>
</div><div class="form-group">
<label for="title"> Enetr Breaking News Details :</label>
<hr>
<textarea class="ckeditor" name="details"><?php echo set_value('details');?></textarea>
<?php echo form_error('details');?>
</div>

<button class="btn btn-success" name="submit" value="submit" type="submit">Add Breaking News</button>
</form><hr>
</div>

я могу добавить данные без изображения успешно, но когда я выбираю изображение, оно не будет добавлять данные и перенаправлять тоже создать страницу без каких-либо сообщений об ошибках и те же проблемы с обновлением тоже

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]