Code Igniter: Upload multiple images - codeigniter-2

My codes:
View
<?php echo form_open_multipart('projects/create') ?>
<label for="pro_video">Project Image</label>
<?php echo form_upload(array('name'=>'pro_image', 'type'=>'file', 'multiple'=>'multiple', 'accept'=>'image/*'))?>
<input type="submit" name="create_project" value="Create" />
</form>
Controller
public function __construct()
{
parent::__construct();
$this->load->library('image_lib');
$this->load->helper(array('form', 'url', 'html'));
$this->load->library('form_validation');
}
public function create()
{
if( sizeof($_FILES['pro_image']) > 0 ){
$config['upload_path'] = './test_upload/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
$this->image_lib->initialize($config);
for( $i = 0; $i < sizeof($_FILES['pro_image']['name']); $i++ ){
$this->upload->do_upload('pro_image');
}
}
}
but it upload last image.. :(
on var_dump($_FILES):
array(1) {
["pro_image"]=>
array(5) {
["name"]=>
array(2) {
[0]=>
string(10) "Desert.jpg"
[1]=>
string(10) "Tulips.jpg"
}
["type"]=>
array(2) {
[0]=>
string(10) "image/jpeg"
[1]=>
string(10) "image/jpeg"
}
["tmp_name"]=>
array(2) {
[0]=>
string(23) "E:\wamp\tmp\phpA235.tmp"
[1]=>
string(23) "E:\wamp\tmp\phpA245.tmp"
}
["error"]=>
array(2) {
[0]=>
int(0)
[1]=>
int(0)
}
["size"]=>
array(2) {
[0]=>
int(845941)
[1]=>
int(620888)
}
}
}

Thanks friends I used HTML5 file tag

Related

How to check if data in a database is true? - Not using Session in CodeIgniter

I'm using CodeIgniter and I've got a function to insert an email address and a code into a database.
I now want the user to post that code and if it is correct, delete it, and if it is not correct, to give the user another try.
I've edited the original coding.
Email Controller - I've deleted reference to sessions and commented out the sending of the email because I'm only testing in localhost. The Email function works good. After posting the Email function I open the database and copy the code which must be correct.
Code Controller - I've deleted reference to sessions. And I now have an email text box in code view, which BTW automatically inserts the email address. I then paste the code into the code text box.
However, despite the code being correct the view('codeincorrect') is selected instead of view('username').
Can somebody tell me what is wrong?
Email Controller
class Email extends CI_Controller
{
public function index()
{
$this->load->model('Email_model', 'email_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'required|min_length[10]|max_length[40]|valid_email|is_unique[tbl_members.email_address]', array(
'required' => 'You have not entered an %s address.', 'min_length' => 'Your %s address must be a minimum of 10 characters.',
'max_length' => 'Your %s address must be a maximum of 40 characters.', 'valid_email' => 'You must enter a valid %s address.',
'is_unique' => 'That %s address already exists in our Database.'));
if ($this->form_validation->run() == FALSE) // The email address does not exist.
{
$this->load->view('email');
}
else
{
$email = $this->input->post('email');
$random_string = chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . chr(rand(65,90));
$code = $random_string;
$this->email_model->insert_email($email, $code);
/*
$this->load->library('email');
$this->email->from('<?php echo WEBSITE_NAME; ?>', '<?php echo WEBSITE_NAME; ?>');
$this->email->to('$email');
$this->email->subject('Code.');
$this->email->message('Select & Copy this code, then return to the website. - ','$code');
$this->email->send();
*/
$this->load->view('code');
}
}
}
Email Model
class Email_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
public function insert_email($email, $code)
{
$data = array('email_address' => $email,'pass_word' => $code);
$this->db->insert('tbl_members', $data);
return $this->db->insert_id();
}
}
Code Controller
class Code extends CI_Controller
{
public function index()
{
$this->load->model('Code_model', 'code_model');
$email = $this->input->post('email');
$code = $this->input->post('code');
$result = $this->code_model->find_code($email, $code);
if ($result)
{
$this->load->view('username');
}
else
{
$this->load->view('codeincorrect');
}
}
}
Code Model
class Code_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
public function find_code($email, $code)
{
$this->db->select('user_id');
$this->db->where('email_address', $email);
$this->db->where('pass_word', $code);
$code = $this->db->get('tbl_members');
if ($code->result())
{
return $this->db->delete('pass_word', $code);
}
}
}
This is the coding in the code view, which maybe causing the problem;
<style type="text/css"> .email-address { position: fixed; width: 100%; text-align: center; top: 30%; } </style>
<div class="email-address">
<input type="text" name="email" value="<?php echo set_value('email'); ?>" style="width: 18%; height: 5mm"; />
<style type="text/css"> .code { position: fixed; width: 100%; text-align: center; top: 55%; } </style>
<div class="code">
<input type="email" class="form-control" name="code" style="width: 15mm; height: 5mm"; />
</div>
<?php echo form_open('code'); ?>
<style type="text/css"> .submit { position: fixed; width: 100%; text-align: center; top: 65%; } </style>
<div class="submit">
<input type="submit" class="btn btn-primary" value="Submit" />
</form></div>
Please try it.
In Controller
public function index()
{
$this->load->model('Code_model', 'code_model');
$code = $this->input->post('code');
// Need to email here.
$email= $this->input->post('email');
$result = $this->code_model->find_code($code,$email);
if ($result)
{
$this->load->view('username');
}
else
{
$this->load->view('codeincorrect');
}
}
In Model
public function find_code($code,$email)
{
$this->db->select('user_id');
$this->db->where('email_address', $email);
$this->db->where('pass_word', $code);
$code = $this->db->get('tbl_members');
if ($code->result()) {
$this->db->delete('pass_word', $code);
}
}
So, your Controller calls the Model correctly but you are not checking the Model function and you are not sending the email field.
So this should be correct:
Controller:
public function index()
{
$this->load->model('Code_model', 'code_model');
$code = $this->input->post('code');
$email= $this->input->post('email');
if ($this->code_model->find_code($code, $email)) {
$this->load->view('username');
} else {
$this->load->view('codeincorrect');
}
}
Model:
public function find_code($code, $email)
{
$this->db->select('user_id');
$this->db->where('email_address', $email);
$this->db->where('pass_word', $code);
$code = $this->db->get('tbl_members')->result();
if ($code->num_rows() >= 1) {
$this->db->delete('pass_word', $code);
}
}
Note:
If what you are trying to do is a password login, that's not how you should do it. Please see this for example: http://www.iluv2code.com/login-with-codeigniter-php.html

validation not working on multiple select

here i have given validation for multiple select and even if i choose value from select field and gave submit then also its telling to select the field and am using codeigniter 3.0.6. searched alot but couldn't find the solution;
Here is my controller
function online_booking() {
$this->form_validation->set_rules('course', 'Course', 'required');
$this->form_validation->set_rules('branch', 'Branch', 'required');
if($crs = $this->input->post('course'))
{
$course = implode(',',$crs);
var_dump($course);
}
if ($this->form_validation->run() == TRUE)
{
$this->load->model('branch_model');
$data = array('course' => $course, 'branch' => $this->input->post('branch'));
$id = $this->branch_model->insert_enquiry($data);
if ($id)
{
$this->session->set_flashdata('message', 'Booking has been Succeed,We will contact you shortly.');
redirect('online-booking');
}
else
{
$this->session->set_flashdata('message', 'Error has been occured,try again.');
redirect('online-booking');
}
}
$data['active'] = 'online';
$data['program'] = $this->home_model->get_program();
$this->load->view('online_bookin', $data);
}
here is my view page
<div class="form-group col-md-6">
<label for="exampleInputEmail1">Course to be opted*</label>
<select class="form-control" name="course[]" id="course" multiple="multiple">
<option value="">Select Course</option>
<?php foreach ($program->result() as $row) if($row->parent_id !=0) {?>
<option value="<?php echo $row->id; ?>" <?php echo set_select('course',$row->id) ?> ><?php echo $row->name; ?></option>
<?php } ?>
</select>
</div>
this is my callback function
function is_multiple_select() {
$crs=$this->input->post('course');
if(!$crs)
{
$this->form_validation->set_message('is_multiple_select','You did not select any course to upload.');
return false;
}
else
{
return true;
}
}
this is my model
public function insert_enquiry($data=array())
{
if($this->db->insert(`enquiryform`,$data))
{
return $this->db->insert_id();
}
else
{
return false;
}
}
Why are you using this code:
if($crs = $this->input->post('course'))
{
$course = implode(',',$crs);
var_dump($course);
}
Remove it and check if it works. Or place it inside the $this->form_validation->run() == TRUE block.
function is_multiple_select() {
$crs=$this->input->post('course');
if(!empty($crs) && count($crs)>0)
{
return true;
}
else
{
$this->form_validation->set_message('is_multiple_select','You did not select any course to upload.');
return false;
}
}
//Changes
if ($this->form_validation->run() == TRUE)
{
//You can't save an array directly.
$data = array('course' => implode(",",$this->input->post('course') ), 'branch' => $this->input->post('branch') );
$this->db->insert(`enquiryform`,$data);
$insert_id = $this->db->insert_id();
}
while retrieving explode the course it.

Laravel 5.2 Flash Old and errors empty after redirect

I have a problem in laravel. This problem it's only in production server, in my local server it's work property. So maybe it's something in the configuration that I don't know.
So when I Send a form, with wrong values the laravel validator system should redirect the user to the form and show the errors.
This is the code my controller:
$rules = array(
'nombre' => 'required|min:3|max:80',
'email' => 'required|email',
'asunto'=>'required|min:3|max:200',
'mensaje'=>'required|min:5|max:1000',
//'g-recaptcha-response' => 'required|recaptcha',
);
$validation = Validator::make($request->all(), $rules);
//si la validación falla redirigimos al formulario de registro con los errores
//y con los campos que nos habia llenado el usuario
if ($validation->fails())
{
return Redirect::to('/#contacto')->withErrors($validation->messages())->withInput();
}
/#contacto is the Home route with the anchor contacto so this should redirect to the home. This is ok.
This is my route.php
Route::get('/', function () {
return view('web.index');
});
Route::post('/contacto/enviar', 'WebController#contacto');
This is my Kernel
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
];
/**
* The application's route middleware groups.
*
* #var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'api' => [
'throttle:60,1',
],
];
This is my view that should show the error result.
<form name="contacto" method="post" action="/contacto/enviar"><input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<div class="col-lg-6 col-sm-5 wow fadeInUp delay-05s">
<div class="form"><font color="#ff0000" size="1"><b>{{$errors->first('nombre', ':message')}}</b></font><input class="input-text" type="text" name="nombre" value="<?=Request::old('nombre', 'Nombre y apellido *');?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"><font color="#ff0000" size="1"><b>{{$errors->first('email', ':message')}}</b></font><input class="input-text" type="text" name="email" value="<?=Request::old('email', 'Correo electrónico *');?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"><font color="#ff0000" size="1"><b>{{$errors->first('telefono', ':message')}}</b></font><br><input class="input-text" type="text" name="telefono" value="<?=Request::old('telefono', 'Teléfono (incluya código de área) *');?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"><font color="#ff0000" size="1"><b>{{$errors->first('asunto', ':message')}}</b></font><input class="input-text" type="text" name="asunto" value="<?=Request::old('asunto', 'Asunto');?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"><font color="#ff0000" size="1"><b>{{$errors->first('mensaje', ':message')}}</b></font><textarea class="input-text text-area" cols="0" rows="0" name="mensaje" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"><?=Request::old('mensaje', 'Escriba aquí el mensaje *');?></textarea><font color="#ff0000" size="1"><b>{{$errors->first('g-recaptcha-response', ':message')}}</b></font>{!! Recaptcha::render(['lang'=>'es']) !!}<input class="input-btn" type="submit" value="ENVIAR"></div>
</div></form>
On the top of my view I have a var_dump(Session::all()) and this is the result allways when I submit the form.
array(3) {
["_token"]=>
string(40) "WrQWk9qTH47QrKD6J0Qld8sOhKcUp8xssGpy0F2g"
["_previous"]=>
array(1) {
["url"]=>
string(25) "http://dsnet.dsnet.com.ar"
}
["flash"]=>
array(2) {
["old"]=>
array(0) {
}
["new"]=>
array(0) {
}
}
In execution of php artisan route:list this is my result, so I have checked that the web middleware is not duplicate.
The estrange thing is that the same code in my local server is working, and in all the form redirect the result are:
array(4) {
["_token"]=>
string(40) "4s1rhoydlH7l84Em792N79ymemNjh4Ep6I8WLNSG"
["errors"]=>
object(Illuminate\Support\ViewErrorBag)#177 (1) {
["bags":protected]=>
array(1) {
["default"]=>
object(Illuminate\Support\MessageBag)#178 (2) {
["messages":protected]=>
array(1) {
["email"]=>
array(1) {
[0]=>
string(40) "The email must be a valid email address."
}
}
["format":protected]=>
string(8) ":message"
}
}
}
["flash"]=>
array(2) {
["new"]=>
array(0) {
}
["old"]=>
array(2) {
[0]=>
string(6) "errors"
[1]=>
string(10) "_old_input"
}
}
["_old_input"]=>
array(7) {
["_token"]=>
string(40) "jzCq4CGGgutPJ3qB2ls1rp7uaiHpcra9Aer1vApC"
["nombre"]=>
string(19) "Nombre y apellido *"
["email"]=>
string(21) "Correo electrónico *"
["telefono"]=>
string(38) "Teléfono (incluya código de área) *"
["asunto"]=>
string(6) "Asunto"
["mensaje"]=>
string(26) "Escriba aquí el mensaje *"
["g-recaptcha-response"]=>
string(0) ""
}
}
I remember that I had the same issue in the local server and I fixed setting the domain configuration on the session config file as null, but this solution doesn't work in the production server. Any Idea?
Finally, I say that the code it's great! There is not problem with the code, but is a problem with the server configuration. I don't know where. But I upload the site to another server and with the setting of the domain = null, of the session configuration work great.

Laravel validation errors are appearing randomly in my view

When I submit my form the validation works randomly, I mean that it sometimes appears and sometimes not, I found out that the validation object is returned by controller but it is not looped in my view always.
here is my code in view:
#if ($errors->any())
<ul class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</ul>
#endif
it randomly shows this:
object(Illuminate\Support\ViewErrorBag)#651 (1) { ["bags":protected]=> array(1) { ["default"]=> object(Illuminate\Support\MessageBag)#643 (2) { ["messages":protected]=> array(12) { ["province_code"]=> array(1) { [0]=> string(36) "The province code field is required." } ["district_code"]=> array(1) { [0]=> string(36) "The district code field is required." } ["training_provider"]=> array(1) { [0]=> string(40) "The training provider field is required." } ["training_center"]=> array(1) { [0]=> string(38) "The training center field is required." } ["classroom"]=> array(1) { [0]=> string(32) "The classroom field is required." } ["course_leader"]=> array(1) { [0]=> string(36) "The course leader field is required." } ["shift"]=> array(1) { [0]=> string(28) "The shift field is required." } ["start_date"]=> array(1) { [0]=> string(33) "The start date field is required." } ["end_date"]=> array(1) { [0]=> string(31) "The end date field is required." } ["start_time"]=> array(1) { [0]=> string(33) "The start time field is required." } ["end_time"]=> array(1) { [0]=> string(31) "The end time field is required." } ["course_conduct_days"]=> array(1) { [0]=> string(42) "The course conduct days field is required." } } ["format":protected]=> string(8) ":message" } } }<!DOCTYPE html>
and then it comes up with empty array!
object(Illuminate\Support\ViewErrorBag)#652 (1) { ["bags":protected]=> array(0) { } }
Do this if the message bag has errors then only they would be printed
#if($errors->has())
<div class="alert alert-danger">
<ul>
#foreach($errors->getMessages() as $messages)
#foreach($messages as $message)
<li>{{$message}}</li>
#endforeach
#endforeach
</ul>
</div>
#endif
Thanks :)
finally I solved this problem, it was a conflict with ajax

how to create form for multple image upload in codeigniter

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());
}
}

Resources