Welcome Guest, Not a member yet? Register   Sign In
file uploading with text and description
#7

[eluser]jojo777[/eluser]
Hi again, I've some of my code here i'll put some parts maybe it can help you.

You are right. If the path is changed it would be a mess to change all the records of the database, so I prefer create a variable for the galleries and define their path, so all of them can be saved in their own directory (If you use some kind clasification like carsgallery, moviesgallery....)

Paths variables.
Code:
Private $upload_path='./assets/images/galerias/';
Private $upload_path_thumbs='./assets/images/galerias/thumbs/';

Now the upload code. In MY_Model(or MY_Controller, i think is better in model) cause was used by many of them.
Code:
// Upload Function
    // Returns $image_data['file_name'] if the upload of the image and its thumb was correct or it will return errors to the controller.
    public function subir_archivo($upload_path, $upload_path_thumbs){
        
        //empieza la subida del archivo  
        $config = array(
                'upload_path' => $upload_path,
                'allowed_types' => 'gif|jpg|png|jpeg',
                'max_size' => 1024*2,
                'max_width' => 1000, // for example
                'max_height' => 1000, // for example
                'remove_spaces' => true,
                'encrypt_name' => true
             );
        
        $this->load->library('upload', $config);
                
        if ( ! $this->upload->do_upload())
        {
            $data = $this->upload->display_errors();
            
            $datos= array (
                
                'file_name' => '',
                'error' => true,
                'data_error' => $data,              
              );
              
            return $datos;
        }else{
            $image_data= $this->upload->data();
            
            $config = array (
                 'source_image' => $image_data['full_path'],
                 'allowed_types' => 'gif|jpg|png|jpeg',
                 'new_image' => $upload_path_thumbs,
                 'maintain_ration' =>  true,
                 'width' => 150, // choose yourself
                 'height' => 100 // choose yourself
                 );
        
            $this->load->library('image_lib', $config);
            $this->image_lib->resize();
                
            
            $datos= array (
                    'file_name' => $image_data['file_name'],
                    'error' => false
                    );
            
            return $datos;
        
        }
        
    }

So now the call that launchs the image upload
Code:
$subida=$this->subir_archivo($this->upload_path, $this->upload_path_thumbs);

$image_name=$subida['file_name'];
$error=$subida['error'];

if($error==true){
$data['error'] = $subida['data_error'];
}

if ($error==false){

      $datos = array (
      'titleImg' => $this->input->post('title', true),
      'descriptionImg' => $this->input->post('description', true),
      'img' => $image_name,
      );

$this->db->insert('galeria_imagenes', $datos);

}

This should be enough for your needs.
This should work (in fact it works actually in a web) but its for single upload, If you need multiple upload at the same time the code have to be revised.

For multiple there are some alternatives, I use a code that uses twitter bootstrat and CI.

Hope the code helps.


Messages In This Thread
file uploading with text and description - by El Forum - 11-09-2012, 10:40 PM
file uploading with text and description - by El Forum - 11-09-2012, 11:09 PM
file uploading with text and description - by El Forum - 11-10-2012, 06:42 AM
file uploading with text and description - by El Forum - 11-10-2012, 11:18 PM
file uploading with text and description - by El Forum - 11-11-2012, 03:42 AM
file uploading with text and description - by El Forum - 11-11-2012, 11:49 AM
file uploading with text and description - by El Forum - 11-11-2012, 02:31 PM
file uploading with text and description - by El Forum - 11-11-2012, 09:07 PM
file uploading with text and description - by El Forum - 11-11-2012, 09:20 PM
file uploading with text and description - by El Forum - 11-12-2012, 01:51 AM
file uploading with text and description - by El Forum - 11-12-2012, 05:43 AM
file uploading with text and description - by El Forum - 11-12-2012, 05:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB