Multiple file upload and save file name with caption to database - El Forum - 02-02-2012
[eluser]Unknown[/eluser]
I am quite new to codeigniter and I'm loving it. My problem is this:
I have a form with multiple file fields to upload images and text fields for captions. I want to save the file names and captions to the database. With the code below that I got from one of the forum topics I am able to upload multiple images and save the names to the database but dont know how to insert the caption.
My form in the view
Code: <?php
echo form_open_multipart('admin/photo_images/add')."\n\n";
for($i = 1; $i < 6; $i++) {
echo "<p><label for='image_img'>Image $i</label>\n";
$data = array('name'=>'image_img', 'id'=>'image_img');
echo form_upload($data) ."</p>\n\n";
echo "<p><label for='imagecaption_img'>Image Caption</label><br />";
$data = array('name'=>'imagecaption_img', 'id'=>'imagecaption_img', 'size'=>25);
echo form_input($data) ."</p>";
}
echo form_hidden('idgal_img', $gallery_id['id_gal']);
echo form_hidden('gallery_name', $gallery_id['galleryname_gal']);
echo form_submit('submit', 'Upload Images', 'id="submitbutton"');
echo form_close();
?>
My model
Code: $pgdir = '.photogalleries/'.str_replace(" ", "_", strtolower($this->input->post('gallery_name')));
$config['upload_path'] = $pgdir.'/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '5120'; //5 meg
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->load->library('image_lib');
//Upload error flag
$error = FALSE;
foreach($_FILES as $key => $value)
{
if (!empty($value['name'])) {
if ($this->upload->do_upload($key)) {
$uploaded = $this->upload->data();
//Creat Thumbnail
$config['image_library'] = 'GD2';
$config['source_image'] = $uploaded['full_path'];
$config['new_image'] = $pgdir.'/thumbs/';
$config['create_thumb'] = TRUE;
$config['quality'] = 75;
$config['maintain_ratio'] = TRUE;
$config['width'] = 100;
$config['height'] = 100;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
$now = date("Y-m-d H:i:s");
//Add Pic Info To Database
$this->db->set('image_img', $uploaded['file_name']);
$this->db->set('idgal_img', $this->input->post('idgal_img'));
$this->db->set('dateuploaded_img', $now);
//Insert Info Into Database
$this->db->insert('photo_images');
} else {
$error = TRUE;
}
}
}
}
Help please anyone!
Thanks for that Bhashkar, I'm quite new to this
Multiple file upload and save file name with caption to database - El Forum - 02-02-2012
[eluser]Bhashkar Yadav[/eluser]
Could you please put your code within code tag it will be easy for forum member to look at code.
|