CodeIgniter Forums
how do i check a image update in model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how do i check a image update in model (/showthread.php?tid=31411)



how do i check a image update in model - El Forum - 06-17-2010

[eluser]amipaxs[/eluser]
Hi,

I have a form for categories data and 1 category image, when i want to edit a field, i want to give the user the chance to change the first uploaded image, when the user doesn't want to upload a new image i have two posibilities, saves data with image info and no save image info at all..

Code:
MODEL

if(!empty($_POST['cat_img'])){ // this check isn't working !!! how can i check whether or not an image has been sent ???
  
        if(!$this->upload->do_upload('cat_img')){
         return $this->session->set_flashdata('mensaje', utf8_decode($this->upload->display_errors()));
        }
    
       $image = $this->upload->data();
      
       $data= array(
       'nombre'     => db_clean($_POST['fnom_cat'],255),
       'desc_corta' => db_clean(utf8_encode($_POST['fdesc1']),255),
       'desc_larga' => db_clean(utf8_encode($_POST['fdesc2']),1000),
       'ruta_img'   => "/uploads/".$image['file_name'],
       'nombre_img' => $image['raw_name'], //nombre sin extension
       'tipo_img'   => $image['image_type'],
       'estado'     => $_POST['festado'],
       'id_padre'   => $_POST['id_padre']
       );
   }else{
        $data= array(
       'nombre'     => db_clean($_POST['fnom_cat'],255),
       'desc_corta' => db_clean(utf8_encode($_POST['fdesc1']),255),
       'desc_larga' => db_clean(utf8_encode($_POST['fdesc2']),1000),
       'estado'     => $_POST['festado'],
       'id_padre'   => $_POST['id_padre']
       );
   }
     $this->db->where('id', $_POST['id']);
     return $this->db->update('categorias', $data);
   }



I can't check whether the field 'cat_img' is empty or not. any ideas??

thanks in advance


how do i check a image update in model - El Forum - 06-17-2010

[eluser]danmontgomery[/eluser]
Use $_FILES, not _POST.

http://www.php.net/manual/en/features.file-upload.post-method.php


how do i check a image update in model - El Forum - 06-17-2010

[eluser]amipaxs[/eluser]
Ok, thanks a lot