⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

delete file from folder



tolaroath2011

tolaroath2011
  • profile picture
  • Member

Posted 13 March 2012 - 09:13 AM

I have used grocery crud for my codeigniter and i know only use to crud to delete file from database but i also want to delete file from folder that store it. e.g: when i uploaded image this image need to store in folder images. So, when i delete this name of the image from database i want to delete also the image from the folder also.
Please anyone help me.
Thanks
Best regard
tola

fastturtle

fastturtle
  • profile picture
  • Member

Posted 02 July 2012 - 20:54 PM

Tola,

Did you ever get this to work? I also need to figure out how to do this.

JB

fdias

fdias
  • profile picture
  • Member

Posted 02 July 2012 - 22:59 PM

I don't understand the problem. When I remove a file from Grocery Crud it DOES get deleted from the folder.
What version of GCRUD are you using?
Make sure you have the proper permissions on the folder to write/read.

fastturtle

fastturtle
  • profile picture
  • Member

Posted 03 July 2012 - 22:20 PM

When I delete a row from the table using Grocery Crud I then would like to write some code to remove (unlink) a related file off the server. Can I use the callback_after_delete and put in some php to unlink the file?

mikelamar

mikelamar
  • profile picture
  • Member

Posted 03 July 2012 - 22:33 PM

Why you don't try the callback_before_delete ? You can do something custom like this:


$crud->callback_before_delete(array($this,'crud_delete_file'));



public function crud_delete_file($primary_key)
{
$row = $this->db->where('id',$primary_key)->get('your_table_name')->row();

unlink('your_folder/uploads/files/'.$row->file_url);

return true;
}

fastturtle

fastturtle
  • profile picture
  • Member

Posted 04 July 2012 - 00:22 AM

Perfect thanks