I want to upload multiple images in one element. I keep getting a "You did not select a file upload" message. Here's what i've done so far;
My html form:
<?php
echo form_open_multipart('properties/create_property_ajax'); ?>
<div class="form-group">
<label class="form-control-label">Price*</label>
<br />
<input type="text" name="price" class="form-control" value="<?php echo set_value('price'); ?>" />
<div class="form-error"><?php echo form_error('price'); ?></div>
</div>
<div class="form-group">
<label class="form-control-label">Upload Featured Image </label><br />
<small>Only JPG and PNG files allowed (max 4MB).</small>
<input type="file" name="featured_image[]" multiple="" class="form-control" accept=".jpeg,.jpg,.png" required />
<div class="form-error"><?php echo $error; ?></div>
</div>
<?php echo form_close(); ?>
My Controller:
public function create_property_ajax()
{
$this->form_validation->set_rules('title', 'Title', 'trim');
$this->form_validation->set_rules('description', 'Description', 'trim|min_length[2]|max_length[800]');
$this->form_validation->set_rules('price', 'Price', 'required');
$this->form_validation->set_rules('state', 'State');
$this->form_validation->set_rules('lga', 'LGA', 'required');
$this->form_validation->set_rules('address', 'Address', 'required');
$this->form_validation->set_rules('amenities[]', 'Other Positions');
//config for file uploads
$config['upload_path'] = 'assets/uploads/properties'; //path to save the files
$config['allowed_types'] = 'jpg|JPG|jpeg|JPEG|png|PNG'; //extensions which are allowed
$config['max_size'] = 1024 * 4; //filesize cannot exceed 4MB
$config['file_ext_tolower'] = TRUE; //force file extension to lower case
$config['remove_spaces'] = TRUE; //replace space in file names with underscores to avoid break
$config['detect_mime'] = TRUE; //detect type of file to avoid code injection
$this->load->library('upload', $config);
if ($this->form_validation->run()) {
if ($_FILES['featured_image']['name'] == "") { //file is not selected
$this->session->set_flashdata('status_msg_error', 'No file selected.');
redirect(site_url('properties/new_property'));
} elseif ((!$this->upload->do_upload('featured_image')) && ($_FILES['featured_image']['name'] != "")) {
//upload does not happen when file is selected
$error = array('error' => $this->upload->display_errors());
$this->new_property($error); //reload page with upload errors
} else { //file is selected, upload happens, everyone is happy
$featured_image = $this->upload->data('file_name');
//generate thumbnail of the image with dimension 500x500
$thumbnail = generate_image_thumb($featured_image, '500', '500');
$this->property_model->add_new_property($featured_image, $thumbnail);
$this->session->set_flashdata('status_msg', 'Property added and published successfully.');
redirect(site_url('properties'));
}
} else {
$this->new_property(); //validation fails, reload page with validation errors
}
}
My Model:
public function add_new_property($featured_image, $thumbnail)
{
$title = ucwords($this->input->post('title', TRUE));
$description = $this->input->post('description', TRUE);
$price = $this->input->post('price', TRUE);
$state = ucwords($this->input->post('state', TRUE));
$lga = $this->input->post('lga', TRUE);
$address = $this->input->post('address', TRUE);
$amenities = implode(", ", $this->input->post('amenities', TRUE));
$data = array(
'title' => $title,
'description' => $description,
'price' => $price,
'state' => $state,
'lga' => $lga,
'address' => $address,
'amenities' => $amenities,
'featured_image' => $featured_image,
'featured_image_thumb' => $thumbnail,
);
$this->db->insert('property', $data);
}
My goal is to be able to upload multiple images in one element or in one row in the database. Please can anyone help point out the issues?
Try this
$this->load->library('upload');
$upload_config = array();
$upload_config['upload_path'] = 'assets/uploads/properties';
$upload_config['allowed_types'] = 'jpg|gif|jpeg|png';
$array_images_uplaoded = array();
$files = $_FILES;
$multi_file = count($_FILES['featured_image']['name']);
for($i=0; $i<$multi_file; $i++)
{
$_FILES['featured_image']['name']= $files['featured_image']['name'][$i];
$_FILES['featured_image']['type']= $files['featured_image']['type'][$i];
$this->upload->initialize($upload_config);
$this->upload->do_upload('featured_image');
$array_images_uplaoded[] = $this->upload->data();
}
print_r($array_images_uplaoded); // uploaded images
Related
Im new to codeigniter and i have a form with 3 input files that i have to upload and get their path , somehow i cant understand how to do it in codeigniter
here is a part of my form
<?php echo form_open_multipart('drivers/create');?>
............................
..............................
..............................
<div class="form-group">
<label for="">Passport</label>
<input class="form-control" type="file" name="passport" value="">
</div>
<div class="form-group">
<label for="">Driving license</label>
<input class="form-control" type="file" name="driving_license" value="">
</div>
<div class="form-group">
<label for="">Cv</label>
<input class="form-control" type="file" name="cv" value="">
</div>
Than in my controller i have 2 functions create() and upload_image() in create function im trying to call upload_image() to get for each input file path
here is my create()
if ($_FILES['passport']) {
$passport = $this->upload_image($_FILES['passport']);
}
if ($_FILES['driving_license']) {
$driving_license = $this->upload_image($_FILES['driving_license']);
}
if ($_FILES['cv']) {
$cv = $this->upload_image($_FILES['cv']);
}
if ($this->form_validation->run() == TRUE) {
$data = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'phone' => $this->input->post('phone'),
'address' => $this->input->post('address'),
'sort_code' => $this->input->post('sort_code'),
'bank_account' => $this->input->post('bank_account'),
'passport_id' => $passport,
'driving_license' => $driving_license,
'cv' => $cv
);
$create = $this->model_drivers->create($data);
}
here i face the problem for upload_image() how to make for each passed file to return the path?
public function upload_image($name = array()){
..................
...................
$config['upload_path'] = 'assets/drivers';
$config['file_name'] = uniqid();
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$data = array('upload_data' => $this->upload->data());
$type = explode('.', $name['name']);
$type = $type[count($type) - 1];
$path = $config['upload_path'].'/'.$config['file_name'].'.'.$type;
return ($data == true) ? $path : false;
Try pass file array and filename in the function:
if ($_FILES['cv']) {
$cv = $this->upload_image($_FILES['cv'], 'cv');
}
And add upload setup before $data = array('upload_data' => $this->upload->data()); in the modified function:
public function upload_image($file = array(), $name = ''){
..................
...................
$config['upload_path'] = 'assets/drivers';
$config['file_name'] = uniqid();
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$this->load->library('upload');
$this->upload->initialize($config);
$this->upload->do_upload($name);
$data = array('upload_data' => $this->upload->data());
$type = explode('.', $file['name']);
$type = $type[count($type) - 1];
$path = $config['upload_path'].'/'.$config['file_name'].'.'.$type;
return ($data == true) ? $path : false;
I want to upload multiple image with different input file with array name.
view :
<form action="" enctype="multipart/form-data" method="post">
<input name="picture[]" class="form-control" style="padding-top: 0;" type="file"/>
<input name="picture[]" class="form-control" style="padding-top: 0;" type="file"/>
<input type='submit' value="upload" />
</form>
controller:
public function index($id=null)
{
$id = $this->input->get('id');
if ($_POST)
{
if ($this->validation())
{
$file = $this->upload_picture();
if ($file['status'] == 'success')
{
echo $this->upload->data('file_name');
}
else
{
echo $file['data'];
echo $file['status'];
$this->session->set_flashdata('alert', alert('error', $file['data']));
}
}
else
{
$this->session->set_flashdata('alert', alert('error', validation_errors()));
}
//redirect($this->agent->referrer());
}
}
private function upload_picture()
{
$config['upload_path'] = './assets/img/page/';
$config['allowed_types'] = 'jpg|png|gif|jpeg';
$config['max_size'] = 125000; // 1 GB
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('picture[]'))
{
return array(
'status' => 'error',
'data' => $this->upload->display_errors()
);
}
else
{
$data = $this->upload->data();
$resize['image_library'] = 'gd2';
$resize['source_image'] = './assets/img/page/'.$data['file_name'];
$resize['maintain_ratio'] = TRUE;
// $resize['width'] = 1920;
// $resize['height'] = 1080;
$this->load->library('image_lib', $resize);
$this->image_lib->resize();
return array(
'status' => 'success',
'data' => $this->upload->data()
);
}
}
private function validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('picture[0]', 'Picture', 'trim');
$this->form_validation->set_rules('picture[1]', 'Picture', 'trim');
$this->form_validation->set_error_delimiters('', '<br>');
return $this->form_validation->run();
}
result in browser always show error that mean return status to error in upload_picture function, I want to get filename that encrypted and store to database like a4b8a0e070128b0a3dabd9e2931f7ae3.jpg not picture.jpg.
codeigniter upload class doesn't support array file name in this way. So either you have to modify upload class file (not recommended to modify core class file), or you have to modify your codes.
You can name the inputs like this: picture_1, picture_2 etc.
In that case, modify upload_picture() method like this way:
foreach($_FILES as $key=>$val){
if(!$this->upload->do_upload($key)){
$return[$key] = $this->upload->display_errors(); //store this in an array and return at the end. array structure is up to you
}else{
$return[$key] = $this->upload->data(); //store this in an array and return at the end. array structure is up to you
}
}
return $return; //
This way you are uploading files one by one using the loop. However, you have to also modify main method as now it is returning multidimensional array. I've given you just an idea...
I have a form with four fileds like contactemail,contactname,category,comments as of now now i have to add image and doc input in a form,using form i have inserted data to db,how to upload image and doc in codeignatior on form submit
images need to upload in image folder and doc in docs folder
Here is my controller
public function form() {
$this->load->helper('form');
$data = $this->login_model->form();
//loading views
load-view-header
load view page
load-view-footer
}
here my model function
public function form() {
$contactemail = $this->input->post('contactemail');
$contactname = $this->input->post('contactname');
$category = $this->input->post('category');
$comments = $this->input->post('comments');
$data = array(
'contactemail' => $email,
'contactname' => $name,
'category' => $category,
'comments' => $comments
);
$this->db->insert('contact', $data);
return $data;
}
Here is an example. This was put together quickly and is completely untested...at best there may be errors and at worst memory has failed me and I totally missed something but may be a useful example. Let me know if it helps?
View:
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<!-- your other form fields for email, name, category, comments can go here-->
<input type="file" name="image" size="20" />
<input type="file" name="doc" size="20" />
<br /><br />
<input type="submit" value="Submit" />
</form>
Controller:
function form()
{
$this->load->helper(array('form', 'url'));
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$data['error'] = "";
//it would be good to be using the form validation class but here is a quick and dirty check for the submit
if (isset($_POST['submit']))
{
if ( ! $this->upload->do_upload('image'))
{
$data['error'] = $this->upload->display_errors();
}
else
{
$image_upload_data = $this->upload->data();
}
unset($config);
$config['upload_path'] = './docs/';
$config['allowed_types'] = 'doc|docx|txt';
$config['max_size'] = '2048';
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('doc'))
{
$data['error'] .= "<br />".$this->upload->display_errors();
}
else
{
$doc_upload_data = $this->upload->data();
}
if(!empty($data['error']))
{
$this->load->view('form', $data);
}
else
{
$contactemail = $this->input->post('contactemail');
$contactname = $this->input->post('contactname');
$category = $this->input->post('category');
$comments = $this->input->post('comments');
$doc_file = $doc_upload_data['full_path'];
$image_file = $image_upload_data['full_path'];
$form_data = array(
'contactemail' => $email,
'contactname' => $name,
'category' => $category,
'comments' => $comments,
'doc_file' => $doc_file
);
$image_data['image_name'] = $image_file;
$this->login_model->form($form_data,$image_data);
$this->load->view('upload_success', $data);
}
}
else
{
$this->load->view('form', $data);
}
}
Model
public function form($form_data,$image_data) {
$this->db->insert('contact', $image_data);
$image_data['d_fk'] = $this->db->insert_id();
$this->db->insert('images', $image_data);
}
I have an editform for editing my company information. I also have a field for uploading a logo. When I click on choose file, and click Submit (the form) It stores the filename in my database as imagename.jpg for example.
I also want to add the image to the folder assets/uploads/. I tried it using the codeigniter upload class, same as I did on my other upload form, but this one does not work. I just don't know why.
Here's my editform:
<?= form_open_multipart('members/update/'.$id);?>
//other fields for editing company
<tr>
<td><?= form_label('Logo:'); ?></td>
<td><input type="file" name="logo" size="20" /></td>
</tr>
<tr>
<td><?= form_submit('submit', 'Opslaan');?> <?= form_reset('reset', 'Reset');?></td>
</tr>
</table>
<?= form_close()?>
My controller:
function update() //de update functie voor bovenstaande functie.
{
$id = $this->uri->segment(3);
$data = array(
'Bedrijfsnaam' => $this->input->post('Bedrijfsnaam'),
'Postcode' => $this->input->post('Postcode'),
'Plaats' => $this->input->post('Plaats'),
'Telefoonnummer' => $this->input->post('Telefoonnummer'),
'Email' => $this->input->post('Email'),
'Website' => $this->input->post('Website'),
'Profiel' => $this->input->post('Profiel'),
'Adres' => $this->input->post('Adres'),
);
if($this->input->post('logo')) { $data['logo'] = $this->input->post('logo'); }
$config['upload_path'] = './assets/uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '';
$config['max_height'] = '';
$config['overwrite'] = TRUE;
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$data = array('upload_data' => $this->upload->data());
}
$this->members_model->updatebedrijf($id, $data);
$b = $this->session->userdata('idbedrijven');
redirect("members/$b");
}
function updatebedrijf($id, $data)
{
foreach($this->input->post('categorieen') as $cat){
$this->db->where('idbedrijven', $id);
$this->db->update('bedrijven', $data);
$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
$this->insert_bedrijfcat1($to_bedrijfcategorieen2);
};
}
My model:
function updatebedrijf($id, $data)
{
foreach($this->input->post('categorieen') as $cat){
$this->db->where('idbedrijven', $id);
$this->db->update('bedrijven', $data);
$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
$this->insert_bedrijfcat1($to_bedrijfcategorieen2);
};
}
It just does not upload. The path is the same as my other uploadfunction. that one works fine.
You have not set field name in the do_upload function
if ( ! $this->upload->do_upload("logo"))
{
$error = array('error' => $this->upload->display_errors());
}else{
$image_data = $this->upload->data();
}
And there is one thing wrong you have a if check for logo field and you are trying to get in post why ?? it should be
if($_FILES['logo']['name'] != '') { $data['logo'] = $_FILES['logo']['name']; }
if ( ! $this->upload->do_upload(?))
You should set file name as argument to upload function, since it is not default 'userfile'?
Not any of the solutions woked. This the way that I came up with.
if ($_FILES['userfile']['name'] != null) {
// upload configuration
$upload_config = array(
'upload_path' => './assets/uploads/',
'allowed_types' => 'jpeg|jpg|png',
'max_size' => 1048576,
'max_width' => 10240,
'max_height' => 7680,
'encrypt_name' => TRUE
);
// load upload library config
$this->load->library('upload', $upload_config);
if (!$this->upload->do_upload()) {
// assign upload errors
$data['upload_errors'] = $this->upload->display_errors();
// load page title
$page['title'] = "Edit Parent";
// fetch parent information
$this->db->select('Database Query');
// info data in row
$data['info'] = $this->db->get()->row();
// load view with page title
$this->load->view('temp/header', $page);
$this->load->view('editParents', $data);
$this->load->view('temp/footer');
} else {
$upload_photo = $this->upload->data();
// profile image
$parent_photo = $upload_photo['file_name'];
}
} else {
// profile image
$parent_photo = $this->input->post('profile_image');
}
At this present point in time I have some code that does the following:
I can edit and I can add a house sale that uploads/edits one image for this particular house and then during the process a thumbnail is created and then the original file name and the thumbnail name is saved to database fields called imagename and imagethumb.
(Note: Add and Edit a seprate pages)
What my idea is:
I will create another page that has the name of the houses fed into a dropdown menu so when one is selected and images are selected they will upload.
What my issue is:
I am getting myself confused as to what would be the best way to modify my database to enable this change.
How would I modify my php code to handle more then one file (How do I handle multiple images and then pass the image for uploading resizing etc ) What is the best option? - within my given idea?
Could I have an example of what I should do so I can work off this.
I have included the model view and controller (As an Example) of my Add Sale but I will also need to edit a image for the respective sale.
Model:
class Sales_model extends CI_Model
{
function __construct() {
parent::__construct();
}
function getSalesPage($id = NULL) {
$query = $this->db->get_where('sales', array('id' => $id), 1);
if($query->num_rows() == 1) return $query->row();
} # End getSalesPage
function getSalesPages($id = NULL) { // $id does nothing
$query = $this->db->get('sales');
if($query->num_rows() > 0) return $query->result();
} # End getSalesPages
function getSalesContent($id = NULL) {
$this->db->where('id', $id);
$query = $this->db->get('sales', 1);
if($query->num_rows() > 0) {
$row = $query->result_array();
return $row;
}else{
return FALSE;
} # End IF
} # End getSalesContent
function addSale($data = NULL) {
$this->db->insert('sales', $data);
return TRUE;
} # End Add Sale
function updateSale($id, $content) { //Content id from being passed
$this->db->where('id', $id); // selecting the $id to update
$update = $this->db->get('sales'); // What does $update = well it = get the db sales
$row = $update->row_array(); // what does $row mean = well it gets the row as an array
if($update->num_rows() > 0) {
if(isset($content['imagename']) && isset($content['thumbname'])) {
#lets delete the image
unlink("/includes/uploads/gallery/".$row['imagename']);
#lets delete the thumb.
unlink("/includes/uploads/gallery/thumbs/".$row['thumbname']);
}
$this->db->where('id', $id);
if($this->db->update('sales', $content))
{
return TRUE;
}
else
{
return FALSE;
}
} # End IF
} # End Update
function deleteSale($id){
$this->db->where('id', $id);
$q = $this->db->get('sales');
$row = $q->row_array();
if ($q->num_rows() > 0){
//delete from the database
$this->db->where('id', $id);
$this->db->delete('sales');
//lets delete the image
unlink("includes/uploads/sales/".$row['imagename']);
//lets delete the thumb.
unlink("includes/uploads/sales/thumbs/".$row['thumbname']);
}//END if num_rows
}//END function deleteSale($id)
} # End Model
View:
<?php
//Setting form attributes
$formAddSale = array('id' => 'addSale', 'name' => 'addSale');
$saleName = array('id' => 'name', 'name' => 'name','class' => 'validate[required[custom[onlyLetterSp]]]', 'value' => set_value('name'));
$saleLocation = array('id' => 'location', 'name' => 'location','class' => 'validate[required[custom[onlyLetterSp]]]', 'value' => set_value('location'));
$saleBedrooms = array('id' => 'bedrooms','name' => 'bedrooms','class' => 'validate[required[custom[number]]]', 'value' => set_value('bedrooms'));
$saleBathrooms = array('id' => 'bathrooms','name' => 'bathrooms','class' => 'validate[required[custom[number]]]', 'value' => set_value('bathrooms'));
$saleCondition = array('id' => 'condition','name' => 'condition','class' => 'validate[required[custom[onlyLetterSp]]]', 'value' => set_value('condition'));
$saleImage = array('id' => 'userfile', 'name'=> 'userfile');
$salePrice = array('id' => 'price','name' => 'price','class' => 'validate[required[custom[number]]]','value' => set_value('price'));
$saleDescription = array('id' => 'description','name' => 'description','class' => '', 'value' => set_value('description'));
$saleSubmit = array('id' => 'submit', 'name'=> 'submit', 'value' => 'Add Sale');
?>
<div id ="formLayout">
<?php
if($success == TRUE) {
echo '<section id = "validation">Sale Added</section>';
}
echo '<section id = "validation">'.$message['imageError'].'</section>';
?>
<?php echo form_open_multipart('admin/addsale/', $formAddSale); ?>
<?php echo form_fieldset(); ?>
<?php echo form_label('Name:','name'); ?>
<?php echo form_input($saleName); ?>
<div id="errorName"><?php echo form_error('name'); ?></div>
<span class="small">Required Field - Text</span>
<?php echo form_label('Location:','location');?>
<?php echo form_input($saleLocation);?>
<div id="errorLocation"><?php echo form_error('location'); ?></div>
<span class="small">Required Field - Text</span>
<?php echo form_label('Bedrooms: ','bedrooms');?>
<?php echo form_input($saleBedrooms);?>
<div id="errorBedrooms"><?php echo form_error('bedrooms'); ?></div>
<span class="small">Required Field - Number</span>
<?php echo form_label('Bathrooms: ','bathrooms');?>
<?php echo form_input($saleBathrooms);?>
<div id="errorBathrooms"><?php echo form_error('bathrooms'); ?></div>
<span class="small">Required Field - Number</span>
<?php echo form_label('Condition: ','condition');?>
<?php echo form_input($saleCondition);?>
<div id="errorCondition"><?php echo form_error('condition'); ?></div>
<span class="small">Required Field - Text</span>
<?php echo form_label('Price: ','price');?>
<?php echo form_input($salePrice);?>
<div id="errorPrice"><?php echo form_error('price'); ?></div>
<span class="small">Required Field - Number</span>
<?php echo form_label('Image: ','userfile');?>
<?php echo form_upload($saleImage);?>
<div id="errorUserfile"><?php echo form_error('userfile'); ?></div>
<span class="small">Required Field - 1MB Max Size</span>
<?php echo form_label('Description: ','description');?>
<div id="errorDescription"><?php echo form_error('description'); ?></div>
<span class="small">Required Field - Text</span>
<?php echo form_textarea($saleDescription);?>
<script type="text/javascript">CKEDITOR.replace('description');</script>
<?php echo form_submit($saleSubmit);?>
<?php echo form_fieldset_close(); ?>
<?php echo form_close(); ?>
</div>
Controller:
class Addsale extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
if(!$this->session->userdata('logged_in'))redirect('admin/home');
# Main Data
$data['title'] = 'Add Sale: ';
//Set Validation
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('location', 'Location', 'trim|required|xss_clean');
$this->form_validation->set_rules('bedrooms', 'Bedrooms', 'trim|numeric|required|xss_clean');
$this->form_validation->set_rules('bathrooms', 'Bathrooms', 'trim|numeric|required|xss_clean');
$this->form_validation->set_rules('condition', 'Condition', 'trim|required|xss_clean');
$this->form_validation->set_rules('description', 'Description', 'trim|required|xss_clean');
$this->form_validation->set_rules('price', 'Price', 'trim|required|xss_clean');
if($this->form_validation->run()) {
//Set File Settings
$config['upload_path'] = 'includes/uploads/sales/';
$config['allowed_types'] = 'jpg|png';
$config['remove_spaces'] = TRUE;
$config['overwrite'] = TRUE;
$config['max_size'] = '1024';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if(!$this->upload->do_upload()) {
$data['message'] = array('imageError' => $this->upload->display_errors());
} // Upload error end
else{
$data = array('upload_data' => $this->upload->data());
$data['success'] = TRUE;
$config['image_library'] = 'GD2';
$config['source_image'] = $this->upload->upload_path.$this->upload->file_name;
$config['new_image'] = 'includes/uploads/sales/thumbs/';
$config['create_thumb'] = 'TRUE';
$config['thumb_marker'] ='_thumb';
$config['maintain_ratio'] = 'FALSE';
$config['width'] = '150';
$config['height'] = '150';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$file_info = $this->upload->data();
$this->db->escape($content);
$content = array(
'name' => $this->input->post('name', TRUE),
'location' => $this->input->post('location', TRUE),
'bedrooms' => $this->input->post('bedrooms', TRUE),
'bathrooms' => $this->input->post('bathrooms', TRUE),
'condition' => $this->input->post('condition', TRUE),
'description' => $this->input->post('description', TRUE),
'price' => $this->input->post('price', TRUE),
'imagename' =>$file_info['file_name'],
'thumbname' =>$file_info['raw_name'].'_thumb'.$file_info['file_ext']
);
$this->sales_model->addSale($content);
}#end else
} # End Form Validation
$data['content'] = $this->load->view('admin/addsale', $data, TRUE);
$data['sales_pages'] = $this->sales_model->getSalesPages();
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$this->load->view('admintemplate', $data);
} # End Index Function
} # End Controller
For handling dropdown, i think its easy one. But related multi upload stuff, you can use something like...
in your view
<?php echo form_label('Image: ','userfile1');?>
<?php echo form_upload('userfile1');?>
<?php echo form_label('Image: ','userfile2');?>
<?php echo form_upload('userfile2');?>
<!-- and so on -->
<span class="small">Required Field - 1MB Max Size</span>
Then in your controller, you can do this way
//Set File Settings
$config['upload_path'] = 'includes/uploads/sales/';
$config['allowed_types'] = 'jpg|png';
$config['remove_spaces'] = TRUE;
$config['overwrite'] = TRUE;
$config['max_size'] = '1024';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
// Validate files for upload section...
$success = array();
$errors = array();
$updload_files = array(
'userfile1' => $_FILES['userfile1'],
'userfile2' => $_FILES['userfile2'],
// You can add more
);
foreach($updload_files as $field => $updload_file)
{
// Only process submitted file
if($updload_file['error'] == 0)
{
// If there is an error, save it to error var
if( ! $this->upload->do_upload($field) )
{
$errors[] = 'Failed to upload '.$field;
}
// Use this to get the new file info if you need to insert it in a database
$success[] = array( 'Success to upload '.$field => $this->upload->data());
}
else
{
$errors[] = $field . ' contain no data';
}
}
// Heres you could gettin know whats happen
var_dump($errors);
var_dump($success);