Adding additional function when deleting a record

chriso0258 20 May, 2016
Hello,
I have placed a _DELETE_:Delete Entry link in my connectivity connection. This works fine to delete the record. However, I have a directory that contains pictures and what I would like to do is to delete the corresponding picture when the record is deleted. I've tried adding a form event in the Actions/edit section so I can set up some scripting in a form to delete the picture but I don't get transferred to the form after the record is deleted.

Is there anyway of adding some scripting to the connectivity connection to include deleting the picture. Or, is there a way to transfer the connection to a form after the record is deleted? Or, do I need to create a form and script all the deleting of the record and picture myself?

Hope this makes some sense.

Thanks for your assistance.
Chris
GreyHead 21 May, 2016
HI Chris,

I'm no expert in CC but I think that the only way to do this is to link to a custom form event and delete the record and the related picture from there. I don't know of any way of getting the CC Delete action to do anything more than the basic deletion.

Another possible solution would be to run a 'house-keeping' form event from a cron job say once a day to check the pictures against the records and delete the pictures where there is no match. Not sure that this is simpler in this case though.

Bob
chriso0258 23 May, 2016
Hi Bob,

Good idea. Thanks. In using your idea I'm now running into the following problem. Regardless of what path I set to the images, I always get this message:
"No such file or directory in /var/www/html/administrator/components/com_chronoforms5/chronoforms/actions/custom_code/custom_code.php(20):eval()'d code on line 22"

It doesn't matter how I configure my code in setting a path, I get the same message. For example:

$path = "/var/www/html/images/staffpics/"
$picture = $path . $form->data[delete]['picture'];
if (is_file($picture))
{
     unlink("$picture");
}


I have echo $picture and ensured it points to the path and image. I've also tried chdir to change the directory and then just set $picture to the file name without the path. In any case, I get the same message stated above.

Any thoughts?

Thanks for your help.
Chris
GreyHead 23 May, 2016
Answer
Hi Chris,

Please try
     unlink($picture);
without the quotes.

Bob
This topic is locked and no more replies can be posted.