I know that this question has been answered many times, but i still have trouble uploading images..
I am using codeigniter 2.1.4. Image upload works fine on localhost, but doesn't work on remote server(linux)
I have already tried these solutions: - Codeigniter upload file not working online but works on localhost
But it still doesn't work.
Any help would be greatly appreciated
//Controller
function add()
{
if(!$this->session->userdata('is_shop_admin')) {
$this->check_access('add');
}
if ($this->input->server('REQUEST_METHOD')=='POST') {
$upload_data = $this->uploader->upload($_FILES);
if (!isset($upload_data['error'])) {
$category_data = array(
'name' => htmlentities( $this->input->post('name')),
'ordering' => htmlentities( $this->input->post('ordering')),
'shop_id' => $this->get_current_shop()->id,
'is_published' => 1
);
if ($this->category->save($category_data)) {
foreach ($upload_data as $upload) {
$image = array(
'parent_id'=>$category_data['id'],
'type' => 'category',
'description' => "",
'path' => $upload['file_name'],
'width'=>$upload['image_width'],
'height'=>$upload['image_height']
);
$this->image->save($image);
}
$this->session->set_flashdata('success','Category is successfully added.');
} else {
$this->session->set_flashdata('error','Database error occured.Please contact your system administrator.');
}
redirect(site_url('categories'));
} else {
$data['error'] = $upload_data['error'];
}
}
$content['content'] = $this->load->view('categories/add',array(),true);
$this->load_template($content);
}
//Model
function save(&$data, $id=false)
{
if (!$id && !$this->exists(array('id' => $id, 'shop_id' => $data['shop_id']))) {
if ($this->db->insert($this->table_name,$data)) {
$data['id'] = $this->db->insert_id();
return true;
}
} else {
$this->db->where('id',$id);
return $this->db->update($this->table_name,$data);
}
return false;
}
//View
<?php
$this->lang->load('ps', 'english');
?>
<ul class="breadcrumb">
<li><a href="<?php echo site_url() . "/dashboard";?>"><?php echo $this->lang->line('dashboard_label')?></a> <span class="divider"></span></li>
<li><a href="<?php echo site_url('categories');?>"><?php echo $this->lang->line('cat_list_label')?></a> <span class="divider"></span></li>
<li><?php echo $this->lang->line('add_new_cat_button')?></li>
</ul>
<?php
$attributes = array('id' => 'category-form','enctype' => 'multipart/form-data');
echo form_open(site_url('categories/add'), $attributes);
?>
<div class="wrapper wrapper-content animated fadeInRight">
<legend><?php echo $this->lang->line('cat_info_lable')?></legend>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label><?php echo $this->lang->line('category_name_label')?>
<a href="#" class="tooltip-ps" data-toggle="tooltip" title="<?php echo $this->lang->line('cat_name_tooltips')?>">
<span class='glyphicon glyphicon-info-sign menu-icon'>
</a>
</label>
<?php echo form_input(array(
'name' => 'name',
'value' => '',
'class' => 'form-control',
'placeholder' => 'Category Name',
'id' => 'name'
)); ?>
</div>
<div class="form-group">
<label><?php echo $this->lang->line('ordering_label')?>
<a href="#" class="tooltip-ps" data-toggle="tooltip" title="<?php echo $this->lang->line('cat_ordering_tooltips')?>">
<span class='glyphicon glyphicon-info-sign menu-icon'>
</a>
</label>
<?php echo form_input(array(
'name' => 'ordering',
'value' => '',
'class' => 'form-control',
'placeholder' => 'Ordering',
'id' => 'ordering'
)); ?>
</div>
<div class="form-group">
<label><?php echo $this->lang->line('cat_photo_label')?>
<a href="#" class="tooltip-ps" data-toggle="tooltip" title="<?php echo $this->lang->line('cat_photo_tooltips')?>">
<span class='glyphicon glyphicon-info-sign menu-icon'>
</a>
</label>
<input class="btn" type="file" name="images1">
</div>
</div>
</div>
<hr/>
<button type="submit" class="btn btn-primary"><?php echo $this->lang->line('save_button')?></button>
<a href="<?php echo site_url('categories');?>" class="btn btn-primary"><?php echo $this->lang->line('cancel_button')?></a>
</form>
</div>
<script>
$(document).ready(function(){
$('#category-form').validate({
rules:{
name:{
required: true,
minlength: 3,
remote: '<?php echo site_url("categories/exists/" . $this->shop->get_current_shop()->id);?>'
}
},
messages:{
name:{
required: "Please fill Category Name.",
minlength: "The length of Category Name must be greater than 4",
remote: "Category Name is already existed in the system."
}
}
});
});
$(function () { $("[data-toggle='tooltip']").tooltip(); });
</script>