<?php
class AddNewsController extends CI_Controller {
public function index(){
$this->load->view('header');
$this->load->view('footer');
$this->load->view('add-news-views');
}
public function add_news_proccess(){
$this->load->library('form_validation');
$this->form_validation->set_rules('news_title', 'News_Title', 'required');
$this->form_validation->set_rules('paragraphs[]', 'paragraphs', 'required');
$this->form_validation->set_rules('tags[]', 'Tags', 'required');
if (empty($_FILES['home_image']['name']))
{
$this->form_validation->set_rules('home_image', 'Document', 'required');
}
if ($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = TRUE;
$config['max_size'] = '1024';
$config['max_width'] = '1024';
$config['max_height'] = '1024';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('home_image'))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
// $this->load->view('upload_form', $error);
}
else
{
$config = array();
$config['upload_path'] = './para_imgs/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = TRUE;
$config['max_size'] = '1024';
$config['max_width'] = '1024';
$config['max_height'] = '1024';
$this->load->library('upload');
$para_img_list = array();
$files = $_FILES;
print_r($_FILES['image_upload']["name"]);
foreach($_FILES['image_upload']["tmp_name"] as $file => $fileArray){
$file_name=$_FILES["image_upload"]["name"][$file];
if($file_name != null){
echo "hii"."<br>";
$_FILES['image_upload']['name'] = $_FILES["image_upload"]["name"][$file];
$_FILES['image_upload']['type'] = $_FILES['image_upload']['type'][$file];
$_FILES['image_upload']['tmp_name'] = $_FILES['image_upload']['tmp_name'][$file];
$_FILES['image_upload']['error'] = $_FILES['image_upload']['error'][$file];
$_FILES['image_upload']['size'] = $_FILES['image_upload']['size'][$file];
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('image_upload'))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
// $this->load->view('upload_form', $error);
}else{
$para_img_list[] = $_FILES['image_upload']['name'][$file];
}
}else{
echo "for default image";
// $this->load->model('Default_image');
// $default_img = $this->Default_image('default_img');
// print_r($default_img);
}
}
$news_data = array('news_title'=>$this->input->post('news_title'),
'news_image'=>$_FILES['home_image']['name'],
'posted_by'=>'shiva',
'status'=>'INACTIVE');
$paragraphs_list = $this->input->post('paragraphs[]');
$paragraphs_img_list = $this->input->post($_FILES['image_upload']['name']);
$tags_list = $this->input->post('tags[]');
$this->load->model('AddNewsModel');
$this->AddNewsModel->addnews($news_data, $para_img_list, $paragraphs_list, $tags_list);
}
}
}
}
?>