Forums

Delete uploaded file

Kronosites 24 Feb, 2016
Hi!

I have a multiple files upload throught Chronoforms + ChronoConnectivy, and all is working perfect (from 1 to 5 files in total).

My question is regarding to DELETE one or more files through chronoforms.
From the database I think I won't have problems: I can add a checkbox and, when this is checked, put a text like "no file" on the database.

But I need to delete this file, physically, from my server.
How can the users delete 1 or more uploaded files from the server through Chronoforms?
GreyHead 24 Feb, 2016
Hi Kronosites,

You'd need a custom code action with PHP something like this:
<?php
jimport('joomla.filesystem.file');
$path = JPATH_SITE.'/path_to/files/folder/';
$file = $form->data['file_name'];
if ( is_file($path.$file) ) {
  JFile::delete($path.$file);
}
?>
!!! not tested and may need debugging !!!

Biob
Kronosites 25 Feb, 2016
Hi again,

I put the code in "On Submit" but it didn't work.
Here you are my code:
    <?php
    jimport('joomla.filesystem.file');
    $path = JPATH_SITE.'/components/com_chronoforms5/chronoforms/uploads/CCT-HerramientaECG1/';
    $file = $form->data['delfile1'];
    If ( is_file($path.$file) ) {
      JFile::delete($path.$file);
    }
    ?>


I put a debugger on Chronoforms and Chronoconnectivity but nothing is showed about it.
GreyHead 26 Feb, 2016
Hi Kronosites,

I see a typo in my code If should be if with a lower-case i - that might fix the problem, otherwise you get to do the debugging.

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