Jump to content

API how to delete files with hook "after page save"?


Recommended Posts

Hello @ all,

I am using a hook method to empty some database tables after the save action under certain conditions. It works just fine for "standard fields" with text, but i run into problems by deleting files (images or other files such as pdf).

Here is the code that I use:

       //clean all up if event is cancelled
        if(($page->template == "events") AND ($page->cancelled == "1")){
            $this->message("Folgende Felder wurden geleert: Einleitungssatz, Hauptteil,...);
            $page->body = "";
            $page->introtext = "";
            foreach($page->downloadrepeater as $p){                
                $p->downloadfield = "";
                $p->downloadfieldtitle = "";
                $p->downloadfiledesc = "";

The fields body and introtext will be deleted as expected.

The file fields are in a repeater field (downloadrepeater). Therefore I use the foreach loop.

The repeaterfield consists of 3 fields:

- the file upload field (=downloadfield)

- the title field for the file (=downloadfieldtitle) and

- the description field (=downloadfiledesc)

The values of the title and the description field will be deleted too - so this works.

The problem is to delete the file of the file upload field. I know that $p->downloadfield = "" is not the right approach but I have tried it also with delete().

Unfortunately I was not able to figure out the right syntax to delete the file too.

Can someone help to get the right api call?

Best regards

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...