[eluser]bidur[/eluser]
Hi all,
I am able to upload a single image to the database(thanks to the CI forum!) But I am not able to upload more than one image file. I need your help.
The working code for doing single image upload is as follows:
CONTROLLER
Code:
<?php
class Form extends Controller {
function index()
{
parent::Controller();
# loaders
$this->load->library('validation','email');
$this->load->helper(array('form', 'url', 'array'));
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
//setting the validation rules
$rules['image'] = "required";
$this->validation->set_rules($rules);
$this->load->model('form_model');
$data = $this->form_model->general();
if ($this->validation->run() == FALSE)
{
$this->load->view('form_view', $data);
}
else
{
$this->upload->do_upload(); //upload the image into the upload directory
$this->load->model('Form_model','', TRUE);
$this->Form_model->add_participant();
}
}
}
?>
MODEL
Code:
<?php
class Form_model extends Model
{
function Form_model()
{
parent::Model();
}
function add_participant()
{
$upload_data = $this->upload->data();
$img_name = $upload_data['file_name'];
$image_path="./uploads/".$img_name;
$fh = fopen($image_path, "r");
$photo= addslashes(fread($fh, filesize($image_path)));
fclose($fh);
$this->load->database();
$dbdata = array(
'id'=>'',
'description' => $img_name,
'photo'=>$photo
);
$this->db->insert('photo', $dbdata);
$image_id = $this->db->insert_id();
}
}
?>
VIEW
Code:
<html>
<head>
<title>Image Upload Form</title>
</head>
<body>
<div class="formArea">
<div class="errors"><?php echo $this->validation->error_string; ?></div>
<?php echo form_open_multipart('form/index'); ?>
<p class="formBold"><label for="userfile">UPLOAD YOUR PHOTO</label></span><br>
<?php echo form_upload($userfile); ?>
<?php echo form_submit('submit', 'Submit'); ?>
<?php echo form_close(); ?>
</body>
</html>
this code can upload a single image file. I need help so that this code can be modified to upload two(more than one) images.
Again, the threads related to multiple file upload in this forum have been using $_FILES. Is it safe to use $_FILES ? Can't we do multiple file upload without using $_FILES.
Thank you.