unlink image from directory |
[eluser]meer[/eluser]
hi to all, im passing image id from my view , getting that id from controller by uri segment,now iwanna delete data from db and image from its directory, fields are deleting fine , but image is still residing in that directory can i done this with same query from the model? im using following codes view <a href="<?php echo base_url(); ?>add_user_controller/delete/<?php echo $row->id; ?>"> controller $id=$this->uri->segment(3); $this->load->model('users_model'); $this->users_model->delete($id); model function delete($id) { $this->db->where('id',$id); $this->db->delete('register'); } what kind of query i needed to delete data from table and image from image folder? thanks in advance
[eluser]Pedro Luz[/eluser]
you can delete the image, but you shouldn't not do that from the model. its beter to return true or false, from the delete function in the model.. if the record has been deleted... and in the controller use the function unlink Code: function delete($id) in the controller: Code: if($this->user_model->delete(5)) to delete the image you just do Code: unlink($filename); take a look at http://pt2.php.net/manual/en/function.unlink.php
[eluser]meer[/eluser]
ok , but how do i get the filename from the same query?
[eluser]Pedro Luz[/eluser]
depends what's the relation betwwen the user and that image? do you have the image filename in a column in a table? http://stackoverflow.com/questions/38923...rom-server
[eluser]meer[/eluser]
yup, i have got that image name from an other query , but i wanna do this with the same query from the model........
[eluser]Pedro Luz[/eluser]
can you post the other code here? from the other query?
[eluser]meer[/eluser]
controller function delete() { $id=$this->uri->segment(3); $this->db->select('image'); $this->db->from('register'); $this->db->where('id',$id); $query = $this->db->get(); foreach($query->result() as $row) { $path=$row->image; unlink("uploads/".$path); $this->load->model('users_model'); $this->users_model->delete($id); } } i wanna do this all in model with one querry |
Welcome Guest, Not a member yet? Register Sign In |