File was not uploading in codeigniter - php

I am uploading images in codeigniter. my file is not getting uploaded. i dont know where i am doing wrong. please find in below code
Html:
<form method="post" enctype="multipart/form-data" action="<?php echo base_url(); ?>assign_user/addStartPopup">
<div class="col-lg-6">
<div class="form-group">
<label for="image">
<input type="radio" id="image" name="start_img" onclick="rightfilefunction(1);" checked> <label for="image"> <span style="top: -2px;position: relative;">Image upload</span></label>
<label for="video" class="green">
<input type="radio" id="video" name="start_img" onclick="rightfilefunction(2);">
<span style="top: -2px;position: relative;">Video</span>
</label>
</div>
<div class="form-group" id="imageId">
<input type="file" name="imageupload" class="form-control">
</div>
<div class="form-group" id="videoId" style="display:none">
<input type="text" name="video_upload" class="form-control">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary"> Save </button>
</div>
</div>
</form>
Model:
public function startPopup(){
$createdOn = date('Y-m-d H:i:s');
if($_FILES['imageupload']['size'] != 0)
{
$files = $_FILES;
$config = array();
$config['upload_path'] = "startpage/";
$config['allowed_types'] = "png|jpg|gif";
$config['max_size'] = "5000";
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('imageupload')){
$imgdata = $this->upload->data();
$image_config=array();
$image_config["image_library"] = "gd2";
$image_config['overwrite'] = TRUE;
$image_config["source_image"] = $imgdata["full_path"];
$image_config['create_thumb'] = FALSE;
$image_config['maintain_ratio'] = TRUE;
$image_config['new_image'] = $imgdata["file_path"].$imgdata["file_name"];
$image_config['quality'] = "95%";
$image_config['width'] = 170;
$image_config['height'] = 170;
$this->load->library('image_lib',$image_config);
$this->image_lib->initialize($image_config);
$this->image_lib->resize();
$logo = 'startpage/'.$imgdata["file_name"];
$query = $this->db->query("INSERT INTO `startpop` (content_view, created_on) VALUES ('$logo', '$createdOn')");
if($query){
return 1;
}
}else
{
echo "not uploaded";
}
}else{
$prv = $this->input->post('video_upload');
$query = $this->db->query("INSERT INTO `startpop` (content_view, created_on) VALUES ('$prv', '$createdOn')");
if($query){
return 1;
}
}
}
Controller:
public function addStartPopup(){
$result = $this->model->startPopup();
if($result > 0){
$data['mgs'] = "Added Successfully ..!";
$this->load->view('admin/startPage',$data);
}
}
From this above code, i am getting the error "not uploaded". can any one tell me where i am doing wrong

Related

Could not edit image from database PDO PHP

I can succesfully save the image from my database using this code
if(isset($_POST['btn-update'])){
$id = $_REQUEST['id'];
$sql = "SELECT * FROM article WHERE id=:id";
$query= $db_con->prepare($sql);
$query->execute(array(':id' => $id));
while($row=$query->fetch(PDO::FETCH_ASSOC)){
$images_ = $row['image'];
$files_ = $row['file'];
}
$file_image = $_FILES['image-files'];
$file_image_Name = $_FILES['image-files']['name'];
$file_image_TmpName = $_FILES['image-files']['tmp_name'];
$file_image_Size = $_FILES['image-files']['size'];
$file_image_Error = $_FILES['image-files']['error'];
$file_image_Type = $_FILES['image-files']['type'];
if(!empty($_FILES['image-files']['tmp_name'])){
//handle first upload
$file_image_Ext = explode('.', $file_image_Name);
$file_image_ActualExt = strtolower(end($file_image_Ext));
$file_image_allowed = array("jpg", "jpeg", "png");
if(in_array($file_image_ActualExt, $file_image_allowed)){
if($file_image_Error === 0){
if($file_image_Size < 1000000){
$file_image_NameNew = "image-".uniqid('',true).'.'.$file_image_ActualExt;
$file_image_Destination = 'uploaded_files/uploaded_files_articles_images/' .$file_image_NameNew;
move_uploaded_file($file_image_TmpName, $file_image_Destination);
}else{
echo "You file size is too big!";
}
}else{
echo "There was an error uploading the file!";
}
}else{
echo "You cannot upload files of this type!";
}
}else{
$file_image_NameNew = '';
}
if($user->InsertArticle($articleTitle,$date_today,$bodyContent,$file_image_NameNew))
{
header("Location:admin-index?UploadedSuccesfully!");
}
}
Now what I am trying to do is edit the image but it seems like my code is missing something and I couldn't figure out why is it not succesfully editing.
Here's my code for editing the image from database
$location = $_FILES['image']['name'];
$fileTmpNameLocation = $_FILES['image']['tmp_name'];
if(!empty($_FILES['image']['tmp_name'])){
//allow file types
$fileExtLocation = explode('.', $location);
$fileActualExtLocation = strtolower(end($fileExtLocation));
$allowedLocation = array("jpg", "jpeg", "png");
if(in_array($fileActualExtLocation, $allowedLocation)){
$fileNameNewLocation = $images_;
$fileDestinationLocation = 'uploaded_files/uploaded_files_articles_images/' .$fileNameNewLocation;
move_uploaded_file($fileTmpNameLocation, $fileDestinationLocation);
}
}else{
$fileNameNewLocation = '';
}
if($user->UpdateFile($id,$title,$content,$fileNameNewLocation)){
$user->Redirect('edit-index.php?UpdatedSuccesfully');
}else{
echo "There's something wrong!";
}
Here's my UpdateFile Method
public function UpdateFile($id,$title, $content, $image){
try{
$stmt = $this->db->prepare("UPDATE article SET title=:title, content=:content, image=:image WHERE id=:id");
$stmt->bindParam(":title", $title);
$stmt->bindParam(":content", $content);
$stmt->bindParam(":image", $image);
$stmt->bindParam(":id", $id);
$stmt->execute();
return $stmt;
}catch(PDOException $ex){
echo $ex->getMessage();
}
}
Could someone help me out please.
EDIT:
<form action = "edit.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="title">Title of the Article</label>
<input type="text" class="form-control" id="title" name="title" value="<?php echo $title; ?>">
<br \>
<label for="bodyContent">Content</label>
<textarea class="form-control" rows="5" id="content" name="content"><?php echo $content; ?></textarea>
<br>
<div class="row">
<div class="col-md-4">
<label for="exampleFormControlFile1">Upload Image Only</label>
<input type="file" name="image" class="form-control-file" id="image">
<div class="col-md-12">
<?php
if(empty($images_)){
//nnothing to display
}else{
echo "<img src='uploaded_files/uploaded_files_articles_images/$images_' class='img-responsive img-rounded'>";
}
?>
</div>
</div>
<div class="col-md-4">
<label for="exampleFormControlFile1">Upload File</label>
<input type="file" name="files" class="form-control-file" id="files">
<div class="col-md-12">
<?php
if(empty($files_)){
//nothing to display
}else{
echo "<a href='uploaded_files/uploaded_files_articles/$files_' download>".$files_."</p>";
}
?>
</div>
</div>
<div class="col-md-4">
<input type="hidden" name="id" value=<?php echo $_GET['id']; ?>>
</div>
</div>
<br>
<button type="submit" name="btn-update" class="btn btn-primary">Update</button>
</div>
</form>

Image Name Not Save In Database in CodeIgniter 3

Hi friends in my code image upload in my folder but it's not saved in database am not knowledge about CI so help me for this
view code for upload image,
<form role="form" method="post" enctype="multipart/form-data">
<fieldset class="form-group">
<input type="hidden" name="txt_hidden" value="" class="form-control">
</fieldset>
<fieldset class="form-group">
<label class="control-label" for="formGroupExampleInput">Add Main Caregory</label>
<input type="text" value="<?php echo set_value('p_name'); ?>" placeholder="Main Category" name="p_name" class="form-control">
</fieldset>
<fieldset class="form-group">
<label class="control-label" for="formGroupExampleInput2">Order</label>
<input type="text" name="order_id" placeholder="Order Id" value="<?php echo set_value('order_id'); ?>" class="form-control" id="formGroupExampleInput2">
</fieldset>
<fieldset class="form-group">
<label class="control-label" for="formGroupExampleInput2">Status ( 0 active , 1 inactive)</label>
<input type="text" name="status" placeholder="Status" value="<?php echo set_value('status'); ?>" class="form-control" id="formGroupExampleInput2">
</fieldset>
<fieldset class="form-group">
<label class="control-label" for="formGroupExampleInput2">Image</label>
<input type="file" name="image" placeholder="Category Image" value="<?php echo set_value('image'); ?>" class="form-control" id="formGroupExampleInput2">
</fieldset>
<div class="form-group">
<button type="submit" class="btn btn-primary">Add Category</button>
</div>
</form>
in My controller
use this for add category with an image
function add_main_category()
{
$this->form_validation->set_rules('p_name', 'Main Category', 'required|is_unique[main_category.p_name]');
$this->form_validation->set_rules('order_id', 'Order Id');
$this->form_validation->set_rules('status', 'Status');
$this->form_validation->set_rules('image', 'Category Image', 'callback_cat_image_upload');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('master/add_main_category');
}
else
{
$p_name = strtolower($this->input->post('p_name'));
$order_id = strtolower($this->input->post('order_id'));
$status = strtolower($this->input->post('status'));
$image = strtolower($this->input->post('image'));
$data = array(
'p_name' => $p_name,
'order_id' => $order_id,
'status' => $status,
'image' => $image
);
$insert = $this->m->CategoryAdd($data);
if($insert){
$this->session->set_flashdata('success_msg','Category Created Successfully!!');
}
else{
$this->session->set_flashdata('error_msg', 'Failed to delete Category');
}
redirect('admin/main_cat');
}
}
and for image upload use this in controller
function cat_image_upload(){
if($_FILES['image']['size'] != 0){
$upload_dir = './uploads/';
if (!is_dir($upload_dir)) {
mkdir($upload_dir);
}
$config['upload_path'] = $upload_dir;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['file_name'] = 'userimage_'.substr(md5(rand()),0,7);
$config['overwrite'] = false;
$config['max_size'] = '5120';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('image')){
$this->form_validation->set_message('cat_image_upload', $this->upload->display_errors());
return false;
}
else{
$this->upload_data['file'] = $this->upload->data();
return true;
}
}
else{
$this->form_validation->set_message('cat_image_upload', "No file selected");
return false;
}
}
table main_category in column image
everything is working only no image name save in database!
help me with this.
Thanks in advance!
You can't store the image in the way you used as:
$image = strtolower($this->input->post('image'));
Get the image file name once it is uploaded. Here is your modified code:
if (!$this->upload->do_upload('image')){
$this->form_validation->set_message('cat_image_upload', $this->upload->display_errors());
return false;
}
else{
$this->upload_data['file'] = $this->upload->data();
$data = array('upload_data' => $this->upload->data());
$doc_file_name = $data['upload_data']['file_name']; // Use this file name to store in database
return true;
}

Codeigniter : how to upload more than one image with codeigniter [duplicate]

This question already has answers here:
Multiple files upload in Codeigniter
(5 answers)
Closed 8 months ago.
I have inilabs school management script, working fine. But I'm trying to modify. I want to upload more than one image in database
Here is add.php
' <?php
if(isset($image))
echo "<div class='form-group has-error' >";
else
echo "<div class='form-group' >";
?>
<label for="photo" class="col-sm-2 control-label col-xs-8 col-md-2">
<?=$this->lang->line("student_photo")?>
</label>
<div class="col-sm-4 col-xs-6 col-md-4">
<input class="form-control" id="uploadFile1" placeholder="Choose File" disabled />
</div>
<div class="col-sm-2 col-xs-6 col-md-2">
<div class="fileUpload btn btn-success form-control">
<span class="fa fa-repeat"></span>
<span><?=$this->lang->line("upload")?></span>
<input id="uploadBtn1" type="file" class="upload" name="image" />
</div>
</div>
<span class="col-sm-4 control-label col-xs-6 col-md-4">
<?php if(isset($image)) echo $image; ?>
</span>
</div>
<?php
if(isset($imageaadhar))
echo "<div class='form-group has-error' >";
else
echo "<div class='form-group' >";
?>
<label for="aadhar" class="col-sm-2 control-label col-xs-8 col-md-2">
<?=$this->lang->line("student_aadhar")?>
</label>
<div class="col-sm-4 col-xs-6 col-md-4">
<input class="form-control" id="uploadFile2" placeholder="Choose File" disabled />
</div>
<div class="col-sm-2 col-xs-6 col-md-2">
<div class="fileUpload btn btn-success form-control">
<span class="fa fa-repeat"></span>
<span><?=$this->lang->line("upload")?></span>
<input id="uploadBtn2" type="file" class="upload" name="imageaadhar" />
</div>
</div>
<span class="col-sm-4 control-label col-xs-6 col-md-4">
<?php if(isset($imageaadhar)) echo $imageaadhar; ?>
</span>
</div>
<?php
if(isset($imagebirthc))
echo "<div class='form-group has-error' >";
else
echo "<div class='form-group' >";
?>
<label for="birthc" class="col-sm-2 control-label col-xs-8 col-md-2">
<?=$this->lang->line("student_birthc")?>
</label>
<div class="col-sm-4 col-xs-6 col-md-4">
<input class="form-control" id="uploadFile3" placeholder="Choose File" disabled />
</div>
<div class="col-sm-2 col-xs-6 col-md-2">
<div class="fileUpload btn btn-success form-control">
<span class="fa fa-repeat"></span>
<span><?=$this->lang->line("upload")?></span>
<input id="uploadBtn3" type="file" class="upload" name="image" />
</div>
</div>
<span class="col-sm-4 control-label col-xs-6 col-md-4">
<?php if(isset($imagebirthc)) echo $imagebirthc; ?>
</span>
</div>'
This is controller/add.php for upload single image. How to modify for upload two more image ?
$classesID = $this->input->post("classesID");
if($classesID != 0) {
$this->data['sections'] = $this->section_m->get_order_by_section(array("classesID" =>$classesID));
} else {
$this->data['sections'] = "empty";
}
$this->data['sectionID'] = $this->input->post("sectionID");
if($_POST) {
$rules = $this->rules();
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == FALSE) {
$this->data["subview"] = "student/add";
$this->load->view('_layout_main', $this->data);
} else {
$sectionID = $this->input->post("sectionID");
if($sectionID == 0) {
$this->data['sectionID'] = 0;
} else {
$this->data['sections'] = $this->section_m->get_allsection($classesID);
$this->data['sectionID'] = $this->input->post("sectionID");
}
$dbmaxyear = $this->student_m->get_order_by_student_single_max_year($classesID);
$maxyear = "";
if(count($dbmaxyear)) {
$maxyear = $dbmaxyear->year;
} else {
$maxyear = date("Y");
}
$section = $this->section_m->get_section($sectionID);
$array = array();
$array["name"] = $this->input->post("name");
$array["dob"] = date("Y-m-d", strtotime($this->input->post("dob")));
$array["sex"] = $this->input->post("sex");
$array["religion"] = $this->input->post("religion");
$array["email"] = $this->input->post("email");
$array["phone"] = $this->input->post("phone");
$array["address"] = $this->input->post("address");
$array["classesID"] = $this->input->post("classesID");
$array["sectionID"] = $this->input->post("sectionID");
$array["section"] = $section->section;
$array["roll"] = $this->input->post("roll");
$array["username"] = $this->input->post("username");
$array['password'] = $this->student_m->hash($this->input->post("password"));
$array['usertype'] = "Student";
$array['parentID'] = $this->input->post('guargianID');
$array['library'] = 0;
$array['hostel'] = 0;
$array['transport'] = 0;
$array['create_date'] = date("Y-m-d");
$array['year'] = $maxyear;
$array['totalamount'] = 0;
$array['paidamount'] = 0;
$array["create_date"] = date("Y-m-d h:i:s");
$array["modify_date"] = date("Y-m-d h:i:s");
$array["create_userID"] = $this->session->userdata('loginuserID');
$array["create_username"] = $this->session->userdata('username');
$array["create_usertype"] = $this->session->userdata('usertype');
$array["studentactive"] = 1;
$new_file = "";
if($_FILES["image"]['name'] !="") {
$file_name = $_FILES["image"]['name'];
$file_name_rename = $this->insert_with_image($this->input->post("username"));
$explode = explode('.', $file_name);
if(count($explode) >= 2) {
$new_file = $file_name_rename.'.'.$explode[1];
$config['upload_path'] = "./uploads/images";
$config['allowed_types'] = "gif|jpg|png";
$config['file_name'] = $new_file;
$config['max_size'] = '1024';
$config['max_width'] = '3000';
$config['max_height'] = '3000';
$array['photo'] = $new_file;
$this->load->library('upload', $config);
if(!$this->upload->do_upload("image")) {
$this->data["image"] = $this->upload->display_errors();
$this->data["subview"] = "student/add";
$this->load->view('_layout_main', $this->data);
} else {
$data = array("upload_data" => $this->upload->data());
$this->student_m->insert_student($array);
$this->session->set_flashdata('success', $this->lang->line('menu_success'));
redirect(base_url("student/index"));
}
} else {
$this->data["image"] = "Invalid file";
$this->data["subview"] = "student/add";
$this->load->view('_layout_main', $this->data);
}
} else {
$array["photo"] = $new_file;
$this->student_m->insert_student($array);
$this->session->set_flashdata('success', $this->lang->line('menu_success'));
redirect(base_url("student/index"));
}
}
} else {
$this->data["subview"] = "student/add";
$this->load->view('_layout_main', $this->data);
}
} else {
$this->data["subview"] = "error";
$this->load->view('_layout_main', $this->data);
}
}
Help me please
your file name
<input id="uploadBtn3" type="file" class="upload" name="image[]" />
in controller
$files = $_FILES;
$count = count($_FILES['uploadfile']['name']);
for($i=0; $i<$count; $i++)
{
$_FILES['uploadfile']['name']= $files['uploadfile']['name'][$i];
$_FILES['uploadfile']['type']= $files['uploadfile']['type'][$i];
$_FILES['uploadfile']['tmp_name']= $files['uploadfile']['tmp_name'][$i];
$_FILES['uploadfile']['error']= $files['uploadfile']['error'][$i];
$_FILES['uploadfile']['size']= $files['uploadfile']['size'][$i];
$this->upload->initialize($this->set_upload_options());//function defination below
$this->upload->do_upload('uploadfile');
$upload_data = $this->upload->data();
$name_array[] = $upload_data['file_name'];
$fileName = $upload_data['file_name'];
$image[] = $fileName;
}
$fileName = $image;

why my image upload doesnt work?

I know my question isn't new but I don't know why it is not working.
In my controller, If is false and my
image doesn't upload and the data of image don't save in database and else is execute.
<form name="f" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>index.php/aparteman/save" role="form">
<!--<input type="text" name="gh" id="gh"></input>-->
<input type="hidden" name="g" id="g" value=<?php echo $insert_id; ?>></input>
<div class="col-md-1"></div>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-primary" onclick="$(this).parent().find('input[type=file]').click();">
<span class="glyphicon-class glyphicon glyphicon-folder-open"></span> Browse</span>
<input onchange="$(this).parent().parent().find('.form-control').html($(this).val().split(/[\\|/]/).pop());" style="display: none; width:50%;" type="file" name="Name1" id="Name1"></input>
</span>
</form>
mycontroller
public function save()
{
$config['upload_path']='/upload/';
$config['allowed_types']= 'gif|jpg|png|jpeg';
$config['max_size']= 2000;
$config['max_width']= 1024;
$config['max_height']= 768;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('Name1'))
{
$data = array('upload_data' => $this->upload->data());
$my_data['photo']=$data['upload_data']['file_name'];
$my_data = array(
'FIDKhane' => $this->input->post('g')
);
$this->load->model('apartemanmodel');
$this->apartemanmodel->insert_images($my_data);
}
else {
echo "...";
}
my model
function insert_images($my_data)
{
$this->db->set('Name1',$my_data['photo']);
$this->db->set('FIDKhane',$my_data['FIDKhane']);
$this->db->insert('imagekhane');
}
Thanks for your helping.
Looks like you have overwrite your variable $my_data. Try to use this code instead:
$my_data = array(
'photo' => $data['upload_data']['file_name'],
'FIDKhane' => $this->input->post('g')
);

upload image to project directory and store other data in database with Codeigniter

I’m working in form to upload image in project folder and store the other data into Database. when I try to submit this form data was submitted and image was not uploaded and one more the image was uploaded and not all of data was stored in database this is my code
model:
function update_news($data) {
extract($data);
$this->db->where('news_id', $news_id);
$this->db->update($table_name, array('title_en' => $title_en, 'title_ar' => $title_ar,'news_date' => $news_date,'image' => $image,'is_visible' => $is_visible,'main_news' => $main_news));
return true;
}
controller
public function update() {
$filename = $this->input->post('image');
$date = DateTime::createFromFormat("Y-m-d", $this->input->post('news_date'));
$data = array(
'table_name' => 'news', // pass the real table name
'news_id' => $this->input->post('news_id'),
'title_en' => $this->input->post('title_en'),
'title_ar' => $this->input->post('title_ar'),
'news_date' => $this->input->post('news_date'),
'image' => $date->format("Y") . '/' . $this->input->post('image'),
'is_visible' => $this->input->post('is_visible'),
'main_news' => $this->input->post('main_news')
);
$this->m_news_crud->update_news($data);
$folderName = 'assets/images/press-news/2015';
$config['upload_path'] = "$folderName";
if (!is_dir($folderName)) {
mkdir($folderName, 0777, TRUE);
}
$config['file_name'] = $this->input->post('image');
$config['overwrite'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload('userfile','image')) {
$error = array('error' => $this->upload->display_errors());
$data['error'] = $error;
$data['title_en'] = $this->input->post('title_en');
$data['title_ar'] = $this->input->post('title_ar');
$data['news_date'] = $this->input->post('news_date');
$data['image'] = base_url('assets/images/press-news/' . $date->format("Y")) . '/' . $this->input->post('image');
$data['is_visible'] = $this->input->post('is_visible');
$data['main_news'] = $this->input->post('main_news');
$data['news_id'] = $this->input->post('news_id');
$this->load->view('admin/news/d_admin_header');
$this->load->view('admin/news/vcrudedit_news', $data);
$this->load->view('admin/news/d_admin_footer');
} else {
$data = array('upload_data' => $this->upload->data());
redirect('c_news_crud/get_news_data', $data);
echo $filename;
}
}
view:
<div class="container">
<div class="col-md-9">
<?php echo form_open('C_news_crud/update', 'role="form" style="margin-top: 50px;"'); ?>
<div class="form-group">
<label for="title_en">Title Name English</label>
<input type="text" class="form-control" id="title_en" name="title_en" value="<?php echo $title_en ?>">
</div>
<div class="form-group">
<label for="title_ar">Title Name Arabic</label>
<input type="text" class="form-control" id="title_ar" name="title_ar" value="<?php echo $title_ar ?>">
</div>
<div class="form-group">
<div class="col-md-4 col-md-offset-4">
<label for="is_visible">is visible</label>
<?php
if ($is_visible == 1) {
$check_visible = 'checked="checked"';
} else {
$check_visible = ' ';
}
?>
<input role="checkbox" type="checkbox" id="is_visible" class="cbox" <?php echo $check_visible; ?> name="is_visible" value="<?php echo $is_visible; ?>">
</div>
<div class="col-md-4">
<label for="main_news">Main Arabic</label>
<?php
if ($main_news == 1) {
$check_main = 'checked="checked"';
} else {
$check_main = ' ';
}
?>
<input role="checkbox" type="checkbox" id="main_news" class="cbox" <?php echo $check_main; ?> name="main_news" value="<?php echo $main_news; ?>">
</div>
</div>
<div class="form-group">
<label for="news_date">News date</label>
<input type="date" class="form-control" id="news_date" name="news_date" value="<?php echo $news_date ?>">
</div>
<div class="form-group">
<label for="image">image</label>
<input type="file" class="form-control" id="image" name="image" value="<?php echo $image ?>">
</div>
<input type="hidden" name="news_id" value="<?php echo $news_id ?>" />
<input type="submit" name="save" class="btn btn-primary" value="Update">
<button type="button" onclick="location.href = '<?php echo site_url('C_news_crud/get_news_data') ?>'" class="btn btn-success">Back</button>
</form>
<?php echo form_close(); ?>
</div>
Make sure the path to the uploading folder is correct and it has write permission.
Make sure you are referring to the correct file input name:
$config['file_name'] = $_FILES['image']['name'];
set your uploading directory as ./assets/images/press-news/2015/
You need to display the error you get so that you know what is causing the error!
if ( ! $this->upload->do_upload()){
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
Codigniter's Upload Class

Categories