Jump to content

via Ad Packs

delete file from folder

folder delete crud

  • Please log in to reply
5 replies to this topic

#1 tolaroath2011

tolaroath2011

    Newbie

  • Members
  • Pip
  • 1 posts

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

#2 fastturtle

fastturtle

    Member

  • Members
  • PipPip
  • 11 posts

Posted 02 July 2012 - 08:54 PM

Tola,

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

JB

#3 fdias

fdias

    grocery CRUD Addict

  • Members
  • PipPipPip
  • 87 posts

Posted 02 July 2012 - 10: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.

#4 fastturtle

fastturtle

    Member

  • Members
  • PipPip
  • 11 posts

Posted 03 July 2012 - 10: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?

#5 mikelamar

mikelamar

    Member

  • Members
  • PipPip
  • 14 posts

Posted 03 July 2012 - 10: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;
}


#6 fastturtle

fastturtle

    Member

  • Members
  • PipPip
  • 11 posts

Posted 04 July 2012 - 12:22 AM

Perfect thanks





Also tagged with one or more of these keywords: folder, delete, crud

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users