I searched a lot but couldn't find an answer to my problem. The set_value() function is not working on the GET form method whereas it is working on POST. I am trying to get the rows from MySQL and I want to use the GET method for this. Can anyone help, please?
view:
<?=form_open('employee_registration/search_employee', ['role'=>'form','method'=>'GET']);?>
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<label>R. No.<span class="required">*</span></label>
<input class="form-control" placeholder="R. No." name="srch_r_no" id="srch_r_no" value="<?=set_value('srch_r_no');?>">
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label>Name<span class="required">*</span></label>
<input class="form-control" placeholder="Name" name="srch_e_name" id="srch_e_name" value="<?=set_value('srch_e_name');?>">
</div>
</div>
</div>
<button type="submit" class="btn btn-primary" name="srch_btn">Search <span class="fa fa-search"></span></button>
<?=form_close();?>
Controller:
public function search_employee()
{
$get = $this->input->get();
unset($get['srch_btn']);
$table = $this->md_emp_reg->search_employee($get);
$this->index('view',$table);
}
model:
public function search_employee($get)
{
$parameters = $this->filter_values($get,"search");
$query = "CALL `sp_select_employee_details`(".$parameters.");";
$grid = $this->table($query);
return $grid;
}
public function filter_values($arr,$type)
{
$arr_keys = array_keys($arr);
$filtered_values = "";
for ($i=0; $i < count($arr); $i++)
{
if ($arr[$arr_keys[$i]] == "" && $type == "search")
{
$arr[$arr_keys[$i]] = "";
}
elseif($arr[$arr_keys[$i]] == "" && $type != "search")
{
$arr[$arr_keys[$i]] = NULL;
}
$filtered_values .= $this->db->escape($arr[$arr_keys[$i]]).",";
}
return rtrim($filtered_values,',');
}
public function table($query)
{
$result = $this->db->query($query);
$r_arr = $result->result_array();
$result_fields_name = $result->list_fields();
$result_num_fields = $result->num_fields();
$result_num_rows = $result->num_rows();
$table = '<table width="100%" class="table table-condensed table-striped table-bordered table-hover" id="dataTables-example"><thead><tr>';
for ($a=0; $a < $result_num_fields; $a++)
{
$table .= "<th>".$result_fields_name[$a]."</th>";
}
$table .="</tr></thead><tbody>";
for ($i=0; $i < count($r_arr) ; $i++)
{
$table .= "<tr>";
for ($j=0; $j < $result_num_fields ; $j++)
{
$table .= "<td>".$r_arr[$i][$result_fields_name[$j]]."</td>";
}
$table .= "</tr>";
}
$table .="</tbody></table>";
$this->db->close();
return $table;
}
Here is the function:
function set_value($field, $default = '', $html_escape = TRUE)
{
$CI =& get_instance();
$value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field))
? $CI->form_validation->set_value($field, $default)
: $CI->input->post($field, FALSE);
isset($value) OR $value = $default;
return ($html_escape) ? html_escape($value) : $value;
}
Removing the form_validation logic as it isn't useful to us we get:
function set_value($field, $default = '', $html_escape = TRUE)
{
$CI =& get_instance();
$value = $CI->input->post($field, FALSE);
isset($value) OR $value = $default;
return ($html_escape) ? html_escape($value) : $value;
}
Exchanging for post we can create our own helper set_value_get(), save it in a helper, load the helper .etc.:
function set_value_get($field, $default = '', $html_escape = TRUE)
{
$CI =& get_instance();
$value = $CI->input->get($field, FALSE);
isset($value) OR $value = $default;
return ($html_escape) ? html_escape($value) : $value;
}
Usage would be the same as set_value.
Related
I have a dependent drop down that get the category on the first drop down and should get the subcategory on the second drop down but the subcategory drop down isn't populated. I have something like this in my Model:
public function category()
{
$response = array();
$this->search(array(), 'date_created');
$this->db->select('*');
$query = $this->db->get('categories');
$response = $query->result_array();
return $response;
}
public function sub_category($parent_id)
{
$query = $this->db->get_where('sub_categories', array('parent_id' => $parent_id));
return $query->result_array();
}
And then something like this on my Controller:
public function edit_product($id)
{
$data['title'] = 'Update Product';
$this->load->view('../admin/template/admin_header');
$products = new Admin_model;
$data['products'] = $products->edit_product($id);
$data['category'] = $this->Admin_model->category();
$data['subcategory'] = $this->Admin_model->sub_category($data['products']->category_id);
$this->load->view('../admin/template/admin_topnav');
$this->load->view('../admin/template/admin_sidebar');
$this->load->view('../admin/products/manage_product', $data);
$this->load->view('../admin/template/admin_footer');
}
function get_subcategory()
{
if ($this->input->post('parent_id')) {
echo $this->Admin_model->get_subcategory($this->input->post('parent_id'));
}
}
public function insert_product()
{
$productData = array();
if ($this->input->post('productData')) {
$this->form_validation->set_rules('category_id', 'Category', 'required');
$this->form_validation->set_rules('sub_category_id', 'Sub Category', 'required');
$this->form_validation->set_rules('product_name', 'Product Name', 'required');
$this->form_validation->set_rules('department', 'Department', 'required');
$this->form_validation->set_rules('description', 'Description', 'trim|required');
$this->form_validation->set_rules('status', 'Status', 'required');
if ($this->form_validation->run() == true) {
$ori_filename = $_FILES['product_image']['name'];
$update_image = time() . "" . str_replace(' ', '-', $ori_filename);
$config = [
'upload_path' => './images/products',
'allowed_types' => 'gif|jpg|png',
'file_name' => $update_image,
];
$this->load->library('upload', $config);
if (!$this->upload->do_upload('product_image')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view(base_url('admin/products'), $error);
} else {
$image = $this->upload->data('file_name');
$productData = array(
'category_id' => $this->input->post('category_id'),
'sub_category_id' => $this->input->post('sub_category_id'),
'product_name' => $this->input->post('product_name'),
'department' => $this->input->post('department'),
'description' => $this->input->post(htmlentities('description')),
'status' => $this->input->post('status'),
'upload_path' => $image
);
$img = new Admin_model;
$img->insert_product($productData);
$this->session->set_flashdata('status', 'Package InsertedSuccesfully');
redirect(base_url('admin/products'));
}
}
}
$data['title'] = 'Insert Product';
$data['category'] = $this->Admin_model->category();
$data['subcategory'] = $this->Admin_model->get_subcategory();
$this->load->view('../admin/template/admin_header');
$this->load->view('../admin/template/admin_topnav');
$this->load->view('../admin/template/admin_sidebar');
$this->load->view('../admin/products/manage_product', $data);
$this->load->view('../admin/template/admin_footer');
}
And then the view:
<div class="form-group">
<label for="" class="control-label"> Category</label>
<select name="category_id" id="category" class="custom-select select">
<option value="">Select Category</option>
<?php
foreach ($category as $row) {
echo '<option value="' . $row['id'] . '"';
if (isset($products) && $row['id'] == $products->category_id) {
echo ' selected';
}
echo '>' . $row['category'] . '</option>';
}
?>
</select>
</div>
<div class="form-group">
<label for="" class="control-label">Sub Category</label>
<select name="sub_category_id" id="subcategory" class="custom-select select">
<option value="">Select Sub Category</option>
<?php
foreach ($subcategory as $row) {
echo '<option value="' . $row['id'] . '"';
if ($row['id'] == $products->sub_category_id) {
echo ' selected';
}
echo '>' . $row['sub_category'] . '</option>';
}
?>
</select>
</div>
And here's the script. I'm not really familiar at AJAX so i tried to ask and get answers here which helps me progress but I still can't populate the subcategory drop down.
<script type="text/javascript">
$(document).ready(function() {
$('#category').change(function() {
var parent_id = $('#category').val();
console.log(parent_id)
if (parent_id != '') {
$.ajax({
url: "<?php echo base_url(); ?>admin/get_subcategory",
method: "POST",
data: {
parent_id: parent_id
},
success: function(data) {
$('#subcategory').html(data);
console.log(data)
}
});
} else {
$('#subcategory').html('<option value="">Select Category First</option>');
}
});
});
Also, here's what I get in the console
The result from $this->Admin_model->sub_category(...) is an array.
echo works on string values only, which is why you're getting the error. You'll need to loop over the result array (in admin/get_subcategory) and print the values one by one. Also surround each value with an <option> tag so the result can be placed in the select box without further modification:
public function get_subcategory() {
if ($this->input->post('parent_id')) {
$subcategories = $this->Admin_model->sub_category($this->input->post('parent_id'));
foreach ($subcategories as $subcategory) {
echo '<option value="'.$subcategory['id'].'">'.$subcategory['sub_category'].'</option>';
}
}
}
Custom filter datatables serverside not working in codeigniter 3 but no error, with join table database ... anyone can help me ? thx
MODEL
Rekap_m.php
var $column_order = array(null, 'bidang', 'skpd', 'kode', 'masalah', 'nomor', 'rincian_masalah', 'tahun_cipta', 'rak', 'dos', 'retensi', 'ket');
var $column_search = array('bidang', 'kode', 'nomor', 'skpd');
var $order = array('id_arsip' => 'asc');
private function _get_datatables_query()
{
if ($this->input->post('bidang')) {
$this->db->where('id_bidang', $this->input->post('bidang'));
}
if ($this->input->post('skpd')) {
$this->db->like('skpd', $this->input->post('skpd'));
}
if ($this->input->post('kode')) {
$this->db->like('kode', $this->input->post('kode'));
}
if ($this->input->post('masalah')) {
$this->db->like('masalah', $this->input->post('masalah'));
}
$this->db->select('*');
$this->db->from('arsip');
$this->db->join('bidang', 'bidang.id_bidang = arsip.id_bidang');
$i = 0;
foreach ($this->column_search as $item) {
if (#$_POST['search']['value']) {
if ($i === 0) {
$this->db->group_start();
$this->db->like($item, $_POST['search']['value']);
} else {
$this->db->or_like($item, $_POST['search']['value']);
}
if (count($this->column_search) - 1 == $i)
$this->db->group_end();
}
$i++;
}
if (isset($_POST['order'])) {
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
} else if (isset($this->order)) {
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
function get_datatables()
{
$this->_get_datatables_query();
if (#$_POST['length'] != -1)
$this->db->limit(#$_POST['length'], #$_POST['start']);
$query = $this->db->get();
return $query->result();
}
function count_filtered()
{
$this->_get_datatables_query();
$query = $this->db->get();
return $query->num_rows();
}
function count_all()
{
$this->db->from('arsip');
return $this->db->count_all_results();
}
public function get_list_bidangs()
{
$this->db->select('*');
$this->db->from('arsip');
$this->db->join('bidang', 'bidang.id_bidang = arsip.id_bidang');
$this->db->order_by('id_arsip', 'asc');
$query = $this->db->get();
$result = $query->result();
$bidangs = array();
foreach ($result as $row) {
$bidangs[] = $row->bidang;
}
return $bidangs;
}
CONTROLLER
Rekap.php
function __construct()
{
parent::__construct();
check_not_login();
$this->load->model('rekap_m');
}
public function index()
{
$bidangs = $this->rekap_m->get_list_bidangs();
$opt = array('' => 'Semua Bidang');
foreach ($bidangs as $id_bidang) {
$opt[$id_bidang] = $id_bidang;
}
$data['form_bidang'] = form_dropdown('', $opt, '', 'id="bidang" class="form-control"');
$this->template->load('template', 'rekap/rekap_data', $data);
}
function ajax_list()
{
$list = $this->rekap_m->get_datatables();
$data = array();
$no = #$_POST['start'];
foreach ($list as $arsip) {
$no++;
$row = array();
$row[] = $no . ".";
$row[] = $arsip->bidang;
$row[] = $arsip->skpd;
$row[] = $arsip->kode;
$row[] = $arsip->masalah;
$row[] = $arsip->nomor;
$row[] = $arsip->rincian_masalah;
$row[] = $arsip->tahun_cipta;
$row[] = $arsip->rak;
$row[] = $arsip->dos;
$row[] = $arsip->retensi;
$row[] = $arsip->ket;
// add html for action
$data[] = $row;
}
$output = array(
"draw" => #$_POST['draw'],
"recordsTotal" => $this->rekap_m->count_all(),
"recordsFiltered" => $this->rekap_m->count_filtered(),
"data" => $data,
);
// output to json format
echo json_encode($output);
}
public function rekap()
{
$this->load->model('bidang_m');
$data['bidang'] = $this->bidang_m->get()->result();
$this->template->load('template', 'rekap/rekap_data', $data);
}
public function del($id)
{
$this->arsip_m->del($id);
if ($this->db->affected_rows() > 0) {
echo "<script>alert('Data Berhasil dihapus'); </script>";
}
echo "<script>window.location='" . site_url('rekap') . "'; </script>";
}
VIEW
rekap_data.php
<div class="row">
<!-- DataTable with Hover -->
<div class="col-lg-12">
<div class="card mb-4">
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<div class="col-md-4 offset-md-4">
<form id="form-filter">
<div class="form-horizontal">
<div class="form-group">
<div class="col-sm-9">
<div class="form-group">
<label for="bidang" class="col-sm-4 control-label">Bidang</label>
<?php echo $form_bidang; ?>
</div>
<div class="form-group">
<label for="skpd" class="col-sm-4 control-label">SKPD</label>
<input type="text" class="form-control" id="skpd">
</div>
<div class="form-group">
<label for="kode" class="col-sm-4 control-label">Kode</label>
<input type="text" class="form-control" id="kode">
</div>
<div class="form-group">
<label for="masalah" class="col-sm-4 control-label">Masalah</label>
<textarea class="form-control" id="masalah"></textarea>
</div>
<div class="form-group">
<button type="button" id="btn-filter" class="btn btn-primary">Filter</button>
<button type="button" id="btn-reset" class="btn btn-default">Reset</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="table-responsive p-3">
<table class="table align-items-center table-flush table-hover" id="dataTableHover">
<thead class="thead-light">
<tr>
<th>#</th>
<th>Bidang</th>
<th>SKPD</th>
<th>Kode</th>
<th>Masalah</th>
<th>Nomor</th>
<th>Rincian</th>
<th>Tahun</th>
<th>Rak</th>
<th>Dos</th>
<th>Retensi</th>
<th>Keterangan</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var table;
$(document).ready(function() {
table = $('#dataTableHover').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "<?php echo site_url('rekap/ajax_list') ?>",
"type": "POST",
"data": function(data) {
data.id_bidang = $('#bidang').val();
data.skpd = $('#skpd').val();
data.kode = $('#kode').val();
data.masalah = $('#masalah').val();
}
},
"columnDefs": [{
"targets": [0],
"orderable": false,
}, ],
});
$('#btn-filter').click(function() {
table.ajax.reload();
});
$('#btn-reset').click(function() {
$('#form-filter')[0].reset();
table.ajax.reload();
});
});
</script>
the code above is the code that I use, there is no error but not working ... is there something wrong with my code, I ask for advice on what corrections if there are errors
I want to save compressed image in laravel upload. I have found a package called "intervention/image". But it has resize functionality not compress.
You can simply make this:
public function compress($source, $destination, $quality = 75) {
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg') {
$image = imagecreatefromjpeg($source);
} elseif ($info['mime'] == 'image/gif') {
$image = imagecreatefromgif($source);
} elseif ($info['mime'] == 'image/png') {
$image = imagecreatefrompng($source);
}
imagejpeg($image, $destination, $quality);
return $destination;
}
The destination can be same the source
<form action="{{route('resizeImagePost')}}" method="POST" enctype="multipart/form-data">
#csrf
<div class="row">
<div class="col-md-12">
<br/>
<input type="file" name="image" placeholder="image" class ="image">
</div>
<div class="col-md-12">
<br/>
<button type="submit" class="btn btn-success">Upload Image</button>
</div>
</div>
</form>
public function resizeImagePost(Request $request)
{
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$image = $request->file('image');
$upload_imagename = time().'.'.$image->getClientOriginalExtension();
$upload_url = public_path('/images').'/'.$upload_imagename;
$filename = $this->compress_image($_FILES["image"]["tmp_name"], $upload_url, 40);
return back()
->with('success','Image Upload successful');
}
public function compress_image($source_url, $destination_url, $quality) {
$info = getimagesize($source_url);
if ($info['mime'] == 'image/jpeg')
$image = imagecreatefromjpeg($source_url);
elseif ($info['mime'] == 'image/gif')
$image = imagecreatefromgif($source_url);
elseif ($info['mime'] == 'image/png')
$image = imagecreatefrompng($source_url);
imagejpeg($image, $destination_url, $quality);
return $destination_url;
}
I have this menu function below that I use to get a list of forums and categories.
Each time i need to get a new level I have to add a foreach loop in the menu function. I would like to be able to only have one or two foreach loops that can get ever level belonging to that forum
Question: How can I Only have one or two foreach loops in my menu
function that can get multiple levels of categories
Menu Function
public function menu() {
$html = '';
$html .= '<select class="form-control">';
$html .= '<option value="0" selected="selected">None</option>';
foreach ($this->get_parent_forums() as $parent) {
if ($parent->pid == '0') {
$html .= '<option value="" class="optionParent">' . $parent->name . '</option>';
foreach ($this->get_child_forums($parent->fid) as $childs) {
if ($childs->pid == $parent->fid) {
$html .= '<option value="" class="optionChild">' .$childs->name. '</option>';
foreach ($this->get_child_forums($childs->fid) as $grandchilds) {
if ($grandchilds->pid == $childs->fid) {
$html .= '<option value="" class="optionChild">' .$grandchilds->name. '</option>';
}
}
}
}
}
}
$html .= '</select>';
return $html;
}
Full Controller Code
<?php
class Forum_management extends MX_Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->model('admin/forum/forum_model');
}
public function add() {
$data['header'] = Modules::run('admin/common/header/index');
$data['footer'] = Modules::run('admin/common/footer/index');
$this->form_validation->set_rules('title', 'title', 'required');
if ($this->form_validation->run() == TRUE) {
$this->forum_model->insert();
}
$data['forums_select'] = $this->menu();
$this->load->view('template/forums/forum_add_view', $data);
}
public function menu() {
$html = '';
$html .= '<select class="form-control">';
$html .= '<option value="0" selected="selected">None</option>';
foreach ($this->get_forums() as $parent) {
if ($parent->pid == '0') {
$html .= '<option value="" class="optionParent">' . $parent->name . '</option>';
foreach ($this->get_child_forums($parent->fid) as $childs) {
if ($childs->pid == $parent->fid) {
$html .= '<option value="" class="optionChild">' .$childs->name. '</option>';
foreach ($this->get_child_forums($childs->fid) as $grandchilds) {
if ($grandchilds->pid == $childs->fid) {
$html .= '<option value="" class="optionChild">' .$grandchilds->name. '</option>';
}
}
}
}
}
}
$html .= '</select>';
return $html;
}
public function get_forums() {
$this->db->select('*');
$this->db->from('forum');
$this->db->where('pid', '0');
$query = $this->db->get();
return $query->result();
}
public function get_child_forums($fid) {
$this->db->select('*');
$this->db->from('forum');
$this->db->where('pid', $fid);
$query = $this->db->get();
return $query->result();
}
public function has_parent($fid) {
$this->db->select('pid');
$this->db->from('forum');
$this->db->where('fid', $fid);
$query = $this->db->get();
if ($query->num_rows() > 0) {
return true;
} else {
return false;
}
}
}
You can use directly option tag in your get_forums($pid) method. I hope it's can helpful for you.
Forum_model.php
<?php
public function get_forums($pid) {
$forums = '';
$this->db->select('*');
$this->db->from('forum');
$this->db->or_where('pid', $pid);
$query = $this->db->get();
foreach($query->result_array() as $result){
$forums .= '<option value="'.$result['fid'].'" class="optionChild">'.$result['name'].'</option>';
$this->get_forums($result['fid'])
}
return $forums;
}
?>
In View Page :
<select name="pid" class="form-control">
<option value="0">None</option>
<?php foreach ($categories as $category) {?>
<option value="<?php echo $category['fid'];?>" class="optionParent"><?php echo $category['name'];?></option>
<?php echo $category['forums']; ?>
<?php } ?>
</select>
I have a solution.
I got the idea from here https://gist.github.com/YavorK/5578b4f1b32fe125e0f7eab214270c30
Some small changes for a select option instead of ul. And made library instead.
<?php
class Forum_select {
private $CI;
public function __construct() {
$this->CI =& get_instance();
}
public function generate($name = 'pid') {
$html = '';
$html .= '<select name="'.$name.'" class="form-control">';
$html .= $this->create_option($this->getforums());
$html .= '</select>';
return $html;
}
function create_option($items, $startingParentId = 0)
{
$htmlOutput = '';
foreach ($items as $item) {
if ($item['pid'] != $startingParentId) {
continue;
}
$htmlOutput .= '<option value="'. $item['fid'] .'">' . $item['name'] . '</option>';
$htmlOutput .= $this->create_option($items, $item['fid']);
}
return $htmlOutput;
}
public function getforums() {
$this->CI->db->select('*');
$this->CI->db->from('forum');
$query = $this->CI->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
} else {
return false;
}
}
}
i have created form for multiple image upload.but not working that form.only one image uploading..i want multiple images are to be upload to folder and save image name in database..
My View File
<html>
<head>
<title>Product Upload</title>
<style>
#container
{
width:750px;
margin:0 auto;
//border:5px solid #000000;
}
#container form input[type="text"] {
height:30px;
}
</style>
</head>
<body>
<div id="container" align="center">
<form name="product" action="<?php echo base_url;?>admin/login/upload" method="POST" enctype="multipart/form-data" class="form-horizontal">
<table>
<h3>Add New Product</h3>
<tr><td>Categories</td><td><select name="catid"><option>Categories</option>
<?php if(isset($category_details))
{foreach($category_details as $keys=>$values){ ?>
<option value="<?php echo $values['cat_id'];?>"><?php echo $values['cat_name'];?></option>
<?php }
}?>
</select></td></tr>
<tr>
<td>Product Name:</td><td><input type="text" name="pname"></td></tr>
<tr><td><input type="file" multiple="true" name="userfile" size="20" /></td></tr>
<tr><td><br>Product Image:</td><td><br><input type="file" name="pimage[]" id="pimage" multiple></td></tr>
<tr><td><br>Description:</td><td><br><textarea name="pdescription"></textarea></td></tr>
<tr><td><br>Price:</td><td><br><input type="text" name="price"></td></tr>
<tr><td colspan="2" align="center"><br><input type="submit" name="submit" value="ADD" class="btn btn-primary"></td></tr>
</table>
</form>
</div>
</body>
</html>
My Controller File
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* #see http://codeigniter.com/user_guide/general/urls.html
*/
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->model('admin/category_model');
$this->load->model('admin/loginauth_model');
$this->load->model('login_model');
$this->load->library('session');
$this->load->helper('url');
$this->load->helper('cookie');
$this->load->library('encrypt');
$this->load->library('image_CRUD');
}
public function index()
{
$this->load->view('admin/login');
}
public function loadproduct()
{
$category_details=$this->category_model->getCategoryDetails();
$outputdata["category_details"]=$category_details;
$this->load->view('admin/product',$outputdata);
}
public function loginAuth()
{
$this->form_validation->set_rules('email','Enter Email','required|trim|max_length[50]|xss_clean');
$this->form_validation->set_rules('password','Enter your Password','required|trim|max_length[50]|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin/login');
}
else
{
$username=$_POST['email'];
$password=$_POST['password'];
$user_details=$this->loginauth_model->logincheck($username,$password);
//print_r($checkauth);
if($user_details)
{
if($this->session->userdata('adminusername'))
{
$adminusername=$this->session->userdata('adminusername');
$outputdata['username']=$adminusername;
}
$category_details=$this->category_model->getCategoryDetails();
$outputdata['category_details']=$category_details;
$this->load->view('admin/dashboard',$outputdata);
}
}
}
public function category()
{
//$this->load->view('admin/category');
$this->form_validation->set_rules('cat_name','category name','required|trim|max_length[50]|xss_clean');
$this->form_validation->set_rules('cat_desc','category description','required|trim|max_length[50]|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin/category');
}
else
{
$addcategory=$this->category_model->addcategory($_POST);
if($addcategory)
{
//**************************pending
$category_details=$this->category_model->getCategoryDetails();
$outputdata['category_details']=$category_details;
//print_r($outputdata);
$this->load->view('admin/categorylist',$outputdata);
}
}
}
public function categorylist()
{
//echo image_url;
$category_details=$this->category_model->getCategoryDetails();
$outputdata['category_details']=$category_details;
$outputdata['image_url']=image_url;
$this->load->view('admin/categorylist',$outputdata);
$this->load->view('admin/category');
}
public function userdetails()
{
$user_details=$this->login_model->userdetails();
$outputdata['user_details']=$user_details;
$this->load->view('admin/userdetails',$outputdata);
}
public function upload()
{
$productname=$_POST["pname"];
$description=$_POST["pdescription"];
$price=$_POST["price"];
$catid=$_POST["catid"];
$name_array = array();
echo $count = count($_FILES['pimage']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++) {
$_FILES['pimage']['name']=$value['name'][$s];
$_FILES['pimage']['type'] = $value['type'][$s];
$_FILES['pimage']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['pimage']['error'] = $value['error'][$s];
$_FILES['pimage']['size'] = $value['size'][$s];
$config['upload_path'] = FCPATH.'img/product_uploads/original/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|GIF|PNG|JPG|JPEG';
$config['max_size'] = '100';
$config['max_width'] = '150';
$config['max_height'] = '180';
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name'];
//$products=$this->category_model->addproduct($catid,$productname,$description,$imagename,$imagesize,$price,$path);
}
$names= implode(',', $name_array);
/* $this->load->database();
$db_data = array('id'=> NULL,
'name'=> $names);
$this->db->insert('testtable',$db_data);
*/ print_r($names);
//echo FCPATH;
//$productname=$_POST["pname"];
// $description=$_POST["pdescription"];
// $price=$_POST["price"];
//$catid=$_POST["catid"];
// $path = FCPATH.'img/product_uploads/original/';
// $valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP","PNG");
// if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
// $imagename = $_FILES['pimage']['name'];
// $imagesize = $_FILES['pimage']['size'];
// list($txt, $ext) = explode(".", $imagename);
//$products=$this->category_model->addproduct($catid,$productname,$description,$imagename,$imagesize,$price,$path);
//print_r($products);
// $tmp = $_FILES['pimage']['tmp_name'];
//if(move_uploaded_file($tmp, $path.$imagename)) {
// $product_details=$this->category_model->getProductDetails();
//print_r($product_details);
//if(isset($products)){
//echo "aa";
// $this->loadproduct();
//}
// }
//else
// {
//echo "Image Upload Failed.";
//}
}
public function logout()
{
$newdata = array(
'adminuser_id' =>'',
'adminusername' =>'',
'adminemail' => '',
'logged_in' => FALSE,
);
$this->session->unset_userdata($newdata);
$this->session->sess_destroy();
$this->index();
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
You can't just add a multiple attrinbute to <input type="file" />, that's not going to work.
You'll have to use a third-party module/plugin, like Uploadify, to get this functionality running.
You could also check this tutorial on how to integrate Uploadify in CodeIgniter (although I can't see anything CodeIgniterish in your code, but you still tagged the question as CI relevant)
a) Instead of writing this <input type="file" multiple="true" name="userfile" size="20" /> write <input type="file" name="userfile[]" size="20" />
b) Inside your controller you can do something like this:
$files = $_FILES;
$count = count($_FILES['userfile']['name']);
for($i=0; $i<$count; $i++)
{
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->upload->initialize($config);
$this->upload->do_upload();
$image_data = $this->upload->data();
}
Use this to open your upload form :
echo form_open_multipart('admin/do_upload');
After put one or more :
<input type="file" name="name" size="20" />
And use a function like that :
public function do_upload() {
$config['upload_path'] = './assets/images/upload/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/images', $error);
} else {
$data = array('upload_data' => $this->upload->data());
}
}