Modifying My Image Uploader - php

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

Related

Uploading multiple images in on element

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

Error submitting a form with upload pic option. PHP Codeigniter

I've been trying to upload a pic to a folder and store its path in the database, my code seems to work correctly, but no it's not, After i click submit button, it goes to a blank page.
Using Inspect element, Network option in my browser, when seeing the parameters sent
I see correct input from the text fields but for the image,
Content-Disposition: form-data; name="myimage"; filename="IMG_8971.JPG"
Content-Type: image/jpeg
Plus some other weirly looking characters and symbols like :
ÿØÿà
CONTROLLER:
private function setup_upload_option()
{
$config = array();
$config['upload_path'] = 'blog/uploads/';
$config['allowed_type']='jpg|jpeg|png|gif';
$config['encrypt_name']= TRUE;
$config['overwrite']=FALSE;
return $config;
}
public function post_new_blog()
{
$this->form_validation->set_rules('title', 'Title of the Blog', 'trim|required');
$this->form_validation->set_rules('desc', 'Content of the Blog', 'trim|required');
$this->form_validation->set_rules('tags', 'Tags fo the blog', 'trim|required');
if($this->form_validation->run()==FALSE) {
$this->session->set_flashdata('fail', validation_errors());
$this->load->view('blogsection/addblog', array('logged_in' => $this->logged_in));
}
else {
$this->load->library('upload');
$files = $_FILES;
$count = count($_FILES['myimage']['name']);
for($i=0; $i<$count ;$i++)
{
$_FILES['myimage']['name'] = $files['myimage']['name'][$i];
$_FILES['myimage']['type'] = $files['myimage']['type'][$i];
$_FILES['myimage']['size'] = $files['myimage']['size'][$i];
$_FILES['myimage']['tmp_name'] = $files['myimage']['tmp_name'][$i];
$this->upload->initialize($this->setup_upload_option());
if($this->upload->do_upload()==TRUE)
{
$data = $this->upload->data();
$config1['image_library'] = 'gd2';
$config1['source_image'] = $data['full_path'];
$config1['new_image'] = 'blog/uploads/thumbs/';
$config1['create_thumb'] = false;
$config1['height'] = 200;
$config['width'] = 200;
$this->load->library('image_lib', $config1);
$this->image_lib->initialize($config1);
$this->image_lib->resize();
$mydata = $this->session->all_userdata();
$dataarray = array(
'blog_title' => $this->input->post('title', true),
'blog_content' => $this->input->post('desc', true),
'blog_tags' => $this->input->post('tags', true),
'blog_image_name' => $data['orig_name'],
'blog_image' => $data['full_path'],
'date_posted' => date(" jS \of F Y "),
'posted_by' => $mydata['username']
);
$this->main_model->save_new_posts($dataarray);
$this->load->view('blogsection/addblog', array('logged_in' => $this->logged_in, 'success' => 'Blog was posted successfully',$dataarray));
}
}
}
}
MODEL:
public function save_new_posts($dataarray)
{
$this->db->insert('blogs', $dataarray);
if($this->db->affected_rows()>0)
{
return true;
}
}
i have code that always works, it is some what different from you method i hope it will help you.
$imgpath='uploads/profile_pic/';
$all_img="";
if($_FILES["profile_pic"]['name'])//form input type file
{
$path_parts = pathinfo($_FILES["profile_pic"]["name"]);
$image_path = $path_parts['filename'].'_'.time().'.'.$path_parts['extension'];
$all_img.=$image_path;
move_uploaded_file($file_tmp=$_FILES["profile_pic"]["tmp_name"],$imgpath."/".$image_path);
$data['cm_user_profile_pic']=$all_img;//store image name in array
}

Not able to retain values after unsuccessful submission of form in codeigniter

I want that in case a form is not submitted properly then the values that had been entered by the user should not get lost. The form is built in codeigniter
View
<?php echo form_open_multipart('user/add_data'); ?>
<?php
$data = array(
'type'=>'text',
'name'=>'name',
'class'=>'form-control',
'required' => 'required',
'value' => set_value('name')
);
?>
<?php echo form_input($data); ?>
<?php
$data = array(
'type'=>'file',
'name'=>'userfile',
'class'=>'fileinput btn-info',
'id'=>'filename3',
'data-filename-placement'=>'inside',
'style' => 'margin-left: 330px',
'title'=>'If any document upload here (* XLS | DOC | PDF | DOCX | XLSX )'
);
echo form_upload($data);
?>
<?php
$data = array(
'type'=>'submit',
'class'=>'btn btn-primary pull-right',
'name'=>'submit',
'content'=>'Submit'
);
echo form_button($data);
?>
<?php echo form_close(); ?>
Controller
public function add_requirement_data() {
$config['upload_path'] = './request/';
$config['allowed_types'] = 'xls|xlsx|doc|docx|pdf';
$config['max_size'] = 9000000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('userfile'))
{
$data = array('upload_data' => $this->upload->data());
if ($data['upload_data']['file_size'] == '0')
{
$this->session->set_flashdata('req_msg', 'Cannot Upload Empty File');
redirect('user/requirement');
}
else
{
if ($this->um->create_requirement_nofile($instanthire_main_id))
{
$this->session->set_flashdata('req_msg', 'Requirment raised successfully');
redirect('user/requirement');
}
}
}
}
Can anyone please tell how to retain values in codeigniter form
By using sessions
Let us consider your name input tag
In your view
<?php
$data = array(
'type'=>'text',
'name'=>'name',
'class'=>'form-control',
'required' => 'required',
'value' => $this->session->userdata('name')
);
?>
And in your controller,
$this->session->set_userdata('name',$this->input->post('name'));
if ($data['upload_data']['file_size'] == '0')
{
$this->session->set_flashdata('req_msg', 'Cannot Upload Empty File');
redirect('user/requirement');
}
else
{
if ($this->um->create_requirement_nofile($instanthire_main_id))
{
$this->session->unset_userdata('name');
$this->session->set_flashdata('req_msg', 'Requirment raised successfully');
redirect('user/requirement');
}
}

codeigniter validation form

upload library
function upload($upload_path = '', $file_name = ''){
$config = $this->config($upload_path);
$this->CI->load->library('upload' ,$config);
//thuc hien upload
if($this->CI->upload->do_upload($file_name)){
$data = $this->CI->upload->data();
}
else{
//khong upload thanh cong
$data = $this->CI->upload->display_error();
}
return $data;
}
function config($upload_path = ''){
//Khai bao bien cau hinh
$config = array();
//thuc mục chứa file
$config['upload_path'] = $upload_path;
//Định dạng file được phép tải
$config['allowed_types'] = 'jpg|png|gif';
//Dung lượng tối đa
$config['max_size'] = '500';
//Chiều rộng tối đa
$config['max_width'] = '1500';
//Chiều cao tối đa
$config['max_height'] = '1500';
//load thư viện upload
$this->CI->load->library('upload', $config);
return $config;
}
edit action
function edit(){
$id = $this->uri->rsegment('3');
$news = $this->news_model->get_info($id);
if(!$news){
$this->session->set_flashdata('message', 'Không tồn tại bài viết này');
redirect(admin_url('news'));
}
$this->data['news'] = $news;
$this->load->library('form_validation'); //load thư viện
$this->load->helper('form'); //load helper
/*===============================================validate và update data===========================================*/
if( $this->input->post() ){
$this->form_validation->set_rules('title' ,'Tiêu đề bài viết ','required');
$this->form_validation->set_rules('content' ,'Nội dung bài viết','required');
if( $this->form_validation-> run()){
$this->load->library('upload_library');
$upload_path = './upload/news';
$upload_data = $this->upload_library->upload($upload_path, 'image');
$image_link = $this->news_model->get_info($id, 'image_link') ;
if( isset($upload_data['file_name']) ){
$image_link = $upload_data['file_name'];
}
$data = array(
'title' => $this->input->post('title'),
'content' => $this->input->post('content'),
'image_link' => $image_link,
'meta_desc' => $this->input->post('meta_desc'),
'meta_key' => $this->input->post('meta_key'),
'created' => now()
);
if($this->news_model->update($news->id , $data)){
$this->session->set_flashdata('message', 'Cập nhật dữ liệu thành công');
}
else{
$this->session->set_flashdata('message', 'Không cập nhật dữ liệu thành công');
}
//chuyển tới trang danh sách quản trị viên
redirect(admin_url('news'));
}
}
$this->data['temp'] = 'admin/news/edit';
$this->load->view('admin/main' , $this->data);
}
I edited the data are not required to upload photos
when I clicked update button without upload file error occurred
$data = $this->CI->upload->display_error();
this is wrong method call. It should be like this
$data = $this->CI->upload->display_errors();

Uploading logo using Codeigniter not working on editform

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

Categories