Welcome Guest, Not a member yet? Register   Sign In
unlink image from directory
#1

[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="&lt;?php echo base_url(); ?&gt;add_user_controller/delete/&lt;?php echo $row-&gt;id; ?&gt;">

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
#2

[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)
{
$this->db->where('id', $id);
$result = $this->db->delete('mytable');

if($result) return true;

return false;
}

in the controller:

Code:
if($this->user_model->delete(5))
{
unlink($filename)
}

to delete the image you just do

Code:
unlink($filename);

take a look at
http://pt2.php.net/manual/en/function.unlink.php
#3

[eluser]meer[/eluser]
ok , but how do i get the filename from the same query?

#4

[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
#5

[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........
#6

[eluser]Pedro Luz[/eluser]
can you post the other code here? from the other query?
#7

[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




Theme © iAndrew 2016 - Forum software by © MyBB