Welcome Guest, Not a member yet? Register   Sign In
Get value from dropdown list and add to controller
#11

[eluser]rad11[/eluser]
Ok I changed for

Code:
$data[$row['folder_name']] = $row['folder_name'];

And question is how i can send
Code:
$row['folder_name']
to

Code:
$config['upload_path'] = './uploads/';

because
Code:
$this->input->post('folder_name);
doesnt work i mean when i add

Code:
$config['upload_path'] = './uploads/' . $this->input->post('folder_name);

It dont add image to selected folder so how I can get the input('folder_name') and send it to controller. You now what I mean?
#12

[eluser]CroNiX[/eluser]
Look at Post #5 and 7, along with the name of the <select> element in your form.

Your form is sending "id_folder", so that's what you need to get via POST, not "folder_name", which doesn't exist anywhere.
Code:
echo form_dropdown('id_folder', $data);
#13

[eluser]CroNiX[/eluser]
Did you get this working?
#14

[eluser]rad11[/eluser]
I did but I do not know how well. I added a method which get id of folder and find a folder_name check it out:

Model

Code:
public function insert_image($id){
        
        $id = $this->input->post('id_folder');
        $query = $this->model_media->get_folder_name_by_id($id);
        foreach ($query as $row){}
        
        $image_data = $this->upload->data();
        
        
        $image_url =  base_url('uploads/'. $row->folder_name . '/' . $image_data['file_name']);
        $image_new = base_url('uploads/images/thumbs/' . $this->input->post('id_folder'));
      
        $data = array(
        'id_folder' => $this->input->post('id_folder'),
        'image_url' => $image_url,
        'thumbs' => $image_new
        );
        

        $query = $this->db->insert('images', $data);
        
        if($query){
        
        return true;
        }else{
        return false;
        }
        
    }

Code:
public function get_folder_name_by_id($id_folder){
        
        $this->db->select('folder_name');
        $this->db->where('id_folder', $id_folder);
        
        $query = $this->db->get('create_folder');
        
        return $query->result();
        
    }

Controller

Code:
function do_upload($id){
    
    if($this->session->userdata('username') == 'admin'){
    
    $id = $this->input->post('id_folder');
    $query = $this->model_media->get_folder_name_by_id($id);
    foreach ($query as $row){}
    
    $config['upload_path'] = './uploads/' . $row->folder_name;
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = 0;
    $config['max_width']  = 0;
    $config['max_height']  = 0;
    
    $this->load->library('upload', $config);
    $this->upload->initialize($config);

if ( ! $this->upload->do_upload()){
    $error = array('error' => $this->upload->display_errors());
    
    redirect('media_ctrl/media_view');
}

View

Code:
&lt;?php

echo form_open_multipart('media_ctrl/do_upload/' . $this->input->post('id_folder'));
echo form_upload('userfile');
echo '<br />';
echo '<br />';
echo '<div>Wybierz do ktorej galerii sciagnac zdjecie</div>';

$data = $this->model_media->show_folders_name();

echo form_dropdown('id_folder', $data);

echo form_submit('upload', 'Upload');
echo form_close();

?&gt;
And its working. Its good or something change ?
#15

[eluser]CroNiX[/eluser]
It looks like you are only retrieving a single result, so you might want to use
Code:
return $query->row();  //returns single row meeting condition

instead of:
Code:
return $query->result(); //returns an array of all rows meeting condition

Then you wouldn't have to do
foreach ($query as $row){}
in order to get the result.

Code:
public function get_folder_name_by_id($id_folder){
        
        $query = $this->db
          ->select('folder_name');
          ->where('id_folder', $id_folder);
          ->get('create_folder')
          ->row(); //get a single row
        
        //return the actual name, or FALSE if not found
        return (isset($query->folder_name)) ? $query->folder_name : FALSE;  
}

Then in your controller you can get rid of that loop that's doing nothing,
Code:
$folder_name = $this->model_media->get_folder_name_by_id($id);

if ($folder_name === FALSE)
{
  //handle error, that folder doesn't exist
}
$config['upload_path'] = './uploads/' . $folder_name;
#16

[eluser]rad11[/eluser]
Ok I try to change Smile




Theme © iAndrew 2016 - Forum software by © MyBB