Forums

Delete file after attachmend send

fection 08 Feb, 2012
Hi there.

Im using the latest version of Chronoforms, thanks for creating this great plugin.
I searched the forum for solutions to my issue, but every solution i tryed didnt solve my problem.

I'm searching for the peace of php code to put in the event to delete the files uploaded after they are send to the email adress given.

Hope somebody could help me out.

T
GreyHead 08 Feb, 2012
Hi fection ,

Which solutions didn't work for you?

Bob
fection 08 Feb, 2012
<?php

$ruta = '/path/to/the/folder/*';
$arxiu = glob($ruta);
array_map('unlink', $arxiu);

?>

replaced path for my path.....but didnt work

Errror:

Language string failed to load: invalid_address: qweqwe
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/tvscreen/domains/xxxxxxxxx.com/public_html/administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(18) : eval()'d code on line 5
Thank you for sending in your arrival form!
fection 09 Feb, 2012
Dear Greyhead.

Have you had the time to check out my problem?

Greets
Fection
GreyHead 09 Feb, 2012
Hi Fection,

It looks to me as though the code is working OK but the path goes to an empty folder. Please check that you have the complete path there.

Bob
fection 09 Feb, 2012
Thank you Greyhead.

Can i use this one? : JOOMLA_PATH/components/com_chronoforms/uploads/FORM_NAME/

Or do you suggest using the core path
fection 09 Feb, 2012
I tryed , and now the this error comes up:

Warning: unlink(components/com_chronoforms/uploads/Arrival/) [function.unlink]: Is a directory in /home/tvscreen/domains/mywebsiteadress.nl/public_html/administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(18) : eval()'d code on line 5
fection 09 Feb, 2012
I know you probably very busy but i hope you find the problem .... im stuck at the moment and cant continue with my project.
GreyHead 09 Feb, 2012
Hi fection,

That isn't an 'Error' it's a PHP 'Warning' (that something *might* be wrong). Do the files get deleted?

Bob
fection 09 Feb, 2012
No, al the files al still there .
GreyHead 10 Feb, 2012
Hi fection,

I tried Googling 'Warning: unlink' and the most common answer seems to be that the Joomla! User (or the FTP User if FTP is enabled for your site) doesn't have delete permission for this folder.

Bob
fection 12 Feb, 2012
But i chmodded the folder the right way.
And ftp is enabled, it CAN delete components and modules folders on uninstall.

So it should have the right permission right?
GreyHead 12 Feb, 2012
Hi fection,

It *should* indeed. But it's not able to delete your files so maybe it hasn't ???

Bob
nml375 12 Feb, 2012
Hi fection & Bob,
Your code is actually trying to remove the directory containing the uploaded files. This is most likely because your glob()-search will also return a reference to any directories matching the pattern, not just files.
In this case, you've probably forgotten to add the asterisk (*) at the end of the pattern, so you are actually matching against the directory itself, not files within the directory.

Further, unlink can only delete files (you'll have to use rmdir to remove an empty directory), and hence you get the warning "Is directory".

Re-check your glob-pattern, and considder adding tests to determine that it's a file and not a directory (to remove the warnings:

$files = glob(JPATH_ADMINISTRATOR . DS . "components/com_chronoforms/uploads/Arrival/*");
foreach ($files as $k => $v)
{
  if (is_file($v))
  {
    unlink($v);
  }
}


/Fredrik
GreyHead 12 Feb, 2012
Hi Fredrik,

Thanks :-)

Bob
fection 13 Feb, 2012
Worked like a charm! So for people with the same problem, just add "*" after your form folder name!

Thank you Greyhead and fredrik!

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