Saturday 5 October 2013

delete Upload Image with ajax


/*
+------------------------------------------------------------------+
Function will be use for delete uploaded image.
@params-> $field : Name of input field name
$table : Name of table in db
$tableId : Name of field name in db
+------------------------------------------------------------------+
*/
function deleteUploaderImage($field, $table, $tableId)
{
//detect ajax request
if($this->input->is_ajax_request()):

//if in edit mode
if($this->input->post('auto_id') != '')
$image = $this->mdl_common->getField($field, $table, $tableId, $this->input->post('auto_id'));
else //simple in form functionality
$image = $this->input->post('path');

//remove image static ajax upload
if(substr_count($image,'./') > 0)
@unlink($image);
else
@unlink('./'.$image);

//thumb image remove
if($this->router->class == 'brochures')
{
$thumb_path = load_thumb_image_nmd($image);
@unlink($thumb_path);
}

//making this field null for edit reference
if($this->input->post('auto_id') != '')
$this->db->set($field,'')->where($tableId,$this->input->post('auto_id'))->update($table);

endif;

}

No comments:

Post a Comment