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

[eluser]meer[/eluser]
can sumone tell me the easy way to unlink an image from the floder
my images are deleting from the db(image file name) bt they are still exixting in the image folder
im using the following codes


view...........

<?php foreach($result as $row ) { ?>
<tr>
<td width="273" height="63" align="center"><img src="&lt;?php echo base_url(); ?&gt;images/&lt;?php echo $row-&gt;image; ?&gt;" height="80" width="120" /></td>
<td width="261" align="center"><a href="admin_controller/delete/&lt;?php echo $row-&gt;id; ?&gt;"><strong>DELETE</strong></a></td>
</tr>
<tr>
<td colspan="2" align="center"><a href="admin_controller/delete/&lt;?php echo $row-&gt;id; ?&gt;"></a>
~~~~~~~~~~~~~~~~~~~~~</td>
</tr>

&lt;?php } ?&gt;


controller.........

function delete()
{
$id=$this->uri->segment(3);
$this->db->delete('add_images',array('id'=>$id));
}


model........

&lt;?php
class Admin_model extends CI_Model{
function set_admin()
{
$this->db->select('id,hover,desc,image,fullpath');
$this->db->from('add_images');
$query = $this->db->get();
//echo $query->result->hover;
if($query->num_rows()>0)
{
//echo "nhuhh"; die;
return $query->result();
}
else
{
return false;
}
}
}


what will be the best way to do this ......plzzzzzzzzz
#2

[eluser]xeroblast[/eluser]
the answer is here :

http://ellislab.com/codeigniter/user-gui...elper.html
#3

[eluser]aquary[/eluser]
it just a normal php function to delete an image....
#4

[eluser]meer[/eluser]
my problem is to unlinking the image from image folder.......
#5

[eluser]meer[/eluser]
i have got the full path

bt still im unable to unlink the image from its folder
some one plz.....
#6

[eluser]boltsabre[/eluser]
What have you tried yet? Native php unlink(), CI file helper delete_files('path')?

Things to keep in mind:
- I'd put it in my model, and call it before you delete it from the database. ONLY delete the image from the DB if your file delete is successful.
- If you are using php unlink(), the path should be relative to the script that is calling it. So you'll have to navigate down a couple of tree levels, then back up the tree to the folder containing the image. So I'd expect it to look something like this:
Code:
$delete = unlink("../../images/uploads/thisismyfile.gif");
if($delete){
   //success, remove from DB now
}else{
   // some kind of error handling, perhaps a flashdata message for the user, logging something
   // whatever tickles your fancy.
}
- I've never personally used the CI File helper, but if you are don't forget to load it first!!! Then I presume it's pretty much the same as unlink, except as per the docs the path is relative from your root/base index.php file, so you'll just have to navigate up your tree from your root folder. Something like this:
Code:
$delete = delete_files('./path/to/directory/myfile.gif');
if($delete){
   // blah blah, same as above.
}
#7

[eluser]meer[/eluser]
thanks alottt

it worked:-)

thanks for your time....




Theme © iAndrew 2016 - Forum software by © MyBB