Cara menggunakan php unlink if exists

Deleting an index deletes its documents, shards, and metadata. It does not delete related Kibana components, such as data views, visualizations, or dashboards.

You cannot delete the current write index of a data stream. To delete the index, you must the data stream so a new write index is created. You can then use the delete index API to delete the previous write index.

(Required, string) Comma-separated list of indices to delete. You cannot specify index aliases.

By default, this parameter does not support wildcards (*) or _all. To use wildcards or _all, set the cluster setting to false.

allow_no_indices

(Optional, Boolean) If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting manage1 returns an error if an index starts with manage2 but no index starts with manage3.

Defaults to manage4.

manage5

(Optional, string) Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as manage6. Valid values are:

manage7Match any data stream or index, including ones.manage8Match open, non-hidden indices. Also matches any non-hidden data stream.manage9Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.0Match hidden data streams and hidden indices. Must be combined with manage8, manage9, or both.3Wildcard patterns are not accepted.

Mohon bantuannya, setelah saya berhasil melakukan upload dan update gambar baru, file yang lama masih ada dalam folder assets padahal sudah pakai unlink tapi tetap gk ada efek di file tersebut ini Controllernya:


 public function det_dosen()
    {
        if($this->session->userdata('akses') =='1'){ 
            $id_login   = $this->input->post('id_login');
            $prodi    = $this->input->post('prodi');
            $jenjang  = $this->input->post('jenjang');
            $ttl      = $this->input->post('ttl');
            $email    = $this->input->post('email');
            $notelp   = $this->input->post('no_telp');
            $alamat   = $this->input->post('alamat');
            $foto = $_FILES['fotopost ']['name'];    
            $old = $this->input->post('fotolama');               

            if (empty($foto)){
                $config['upload_path']      = './assets/img/profile';
                $config['allowed_types']    = 'jpg|png|jpeg';
                $config['max_size']        = 2048;

                $this->load->library('upload',$config);
                $this->upload->initialize($config);
                if(!$this->upload->do_upload('fotopost')){
                    echo $this->upload->display_errors(); die();
                }
                else{
                    $foto = $this->upload->data('file_name');                
                }

                $data = array(      
                    'prodi'         => $prodi,
                    'jenjang_pend'  => $jenjang,
                    'alamat'        => $alamat,
                    'ttl'           => $ttl,
                    'no_telp'       => $notelp,
                    'email'         => $email,                                                                   
                    'profile'       => $foto 
                );               
                $this->m_admin->input_detdosen($id_login, $data);
            }
            else{
                $config['upload_path']      = './assets/img/profile';
                $config['allowed_types']    = 'jpg|png|jpeg';
                $config['max_size']        = 2048;

                $this->load->library('upload',$config);
                $this->upload->initialize($config);
                if(!$this->upload->do_upload('fotopost')){
                    echo $this->upload->display_errors(); die();
                }
                else{
                    $foto = $this->upload->data('file_name');                
                }

                $data = array(      
                    'prodi'         => $prodi,
                    'jenjang_pend'  => $jenjang,
                    'alamat'        => $alamat,
                    'ttl'           => $ttl,
                    'no_telp'       => $notelp,
                    'email'         => $email,                                                                   
                    'profile'       => $foto
                );
               $path = './assets/img/profile/'.$old;
                unlink($path);
                
                $this->m_admin->input_detdosen($id_login, $data);            
            }                      
            redirect('admin/show_dosen/'.$id_login);             
                                
        }else{
            redirect('login');
        }                                
    } 
Dan ini Model:

function input_detdosen($id_login, $data){	
        $this->db->where('id_login',$id_login);
        return $this->db->update('data_dosen', $data);  
    }
Input di index: