Welcome Guest, Not a member yet? Register   Sign In
Unlink only if there is a new image to upload
#2

[eluser]darrentaytay[/eluser]
You will need to do add a snippet along the lines of this to your controller. Basically, this only adds your image data to your array that you pass to the model if a new image has been presented.

Code:
if (!empty($_POST['userfile']['name']))
{
  // call the upload function
  // if the upload function succeeds
  // pass the image information to the model
  if ($this->upload->do_upload())
  {
      $content['imagename'] => $file_info['file_name'];
      $content['thumbname'] => $file_info['raw_name'].'_thumb'.$file_info['file_ext'];
  }
}

Now we can check if there is a new image in the model by simply testing if the imagename & thumbname keys are passed through.

MODEL:

Code:
function updateSale($id, $content) {
            $this ->db->where('id', $id);  
            $update = $this->db->get('sales');
            $row = $update->row_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->update('sales', $content);
            } # End IF
        } #


Messages In This Thread
Unlink only if there is a new image to upload - by El Forum - 05-06-2011, 11:12 PM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 01:12 AM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 01:15 AM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 01:35 AM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 02:20 AM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 02:36 AM
Unlink only if there is a new image to upload - by El Forum - 05-07-2011, 02:38 AM
Unlink only if there is a new image to upload - by El Forum - 05-08-2011, 06:35 PM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 12:49 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 12:57 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 01:41 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 01:58 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:07 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:18 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:22 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:27 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:35 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:50 AM
Unlink only if there is a new image to upload - by El Forum - 05-09-2011, 02:55 AM
Unlink only if there is a new image to upload - by El Forum - 05-10-2011, 02:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB