0

This my code controllers "contract.php"

function delete($con_id){
        //$year=$this->session->userdata('year');
        $path = ('/assets/upload/employees/contracts/');
        $get_file = $path.$con_id.'.jpg';
        $this->db->where('con_id',$con_id);
        $this->db->delete('sch_emp_contract');
        if(file_exists($get_file)){
            unlink(base_url("/assets/upload/employees/contracts/'.$con_id."));
        }

        $m='';
        $p='';
        if(isset($_GET['m'])){
            $m=$_GET['m'];
        }
        if(isset($_GET['p'])){
            $p=$_GET['p'];
        }

        redirect("employee/contract?m=$m&p=$p");
    }

This code View contract_list.php - Button Delete

<td width="1%" class="remove_tag">';
     if($this->green->gAction("D")){
     $tr .='<a title="Delete Contract" id="clk_del" class="clk_del">
<img rel="'.$contract['con_id'].'" src="'.site_url('../assets/images/icons/delete.png').'" onclick="delete_contrac (event);" style="width:20px;height:20px;"></a>';}$tr .='</td>

Function

function delete_contract(event){
    var r = confirm("Are you sure to delete this record !");
    if( r == true){
    var contr_id= $(event.target).attr('rel');
    location.href="<?PHP echo site_url('employee/contract/delete');?>/"+contr_id+"?<?php echo "m=$m&p=$p" ?>";
    }
}

Success Delete from Database but Folder file and Image upload can't delete.

2 Answers 2

1

base_url() function returns url of you project but here you have to use directory path of file which you want to delete.

$path = BASEPATH.'/assets/upload/employees/contracts/';
$get_file = $path.$con_id.'.jpg';
if(file_exists($get_file)){
   unlink($get_file);
}

instead of unlink(base_url("/assets/upload/employees/contracts/'.$con_id."));

Sign up to request clarification or add additional context in comments.

Comments

1

Check if your file_exists returns true or false. Then try something like this.

$path = BASEPATH.'/assets/upload/employees/contracts/';//get absolute path
        $get_file = $path.$con_id.'.jpg';
        $this->db->where('con_id',$con_id);
        $this->db->delete('sch_emp_contract');
        if(file_exists($get_file)){
            unlink($get_file);
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.