I misunderstood what you want to do. I thought you were just trying to remove files that are already marked as deleted, but now I see that you want to both remove the record for the file from APP_DOCUMENT table and delete the file from the server. For that you can use this code:
Code: Select all$caseId = @@APPLICATION;
$query = "SELECT * FROM APP_DOCUMENT WHERE APP_UID='$caseId' AND APP_DOC_FIELDNAME='c_InstallerInvoice'";
$aDocs = executeQuery($query);
if (!is_array($aDocs)) {
throw new Exception("Error in query: $query");
}
$d = new AppDocument();
foreach ($aDocs as $aDoc) {
$aFileInfo = $d->Load($aDoc['APP_DOC_UID'], $aDoc['DOC_VERSION']);
//If Output Document file:
if ($aFileInfo['APP_DOC_TYPE'] == 'OUTPUT') {
$path = PATH_DOCUMENT . G::getPathFromUID($caseId) . PATH_SEP .'outdocs'. PATH_SEP .
$aDoc['APP_DOC_UID'] . '_' . $aDoc['DOC_VERSION'];
if (file_exists($path . '.doc'))
unlink($path . '.doc');
if (file_exists($path . '.pdf'))
unlink($path . '.pdf');
}
else { //if Input Document or attached file:
$ext = pathinfo($aFileInfo['APP_DOC_FILENAME'], PATHINFO_EXTENSION);
$path = PATH_DOCUMENT . G::getPathFromUID($caseId) . PATH_SEP .
$aDoc['APP_DOC_UID'] . '_' . $aDoc['DOC_VERSION'] . '.' .$ext;
unlink($path);
}
$query = "DELETE FROM APP_DOCUMENT WHERE APP_UID='$caseId' AND APP_DOC_FIELDNAME='c_InstallerInvoice'";
executeQuery($query);
}
If you just want to mark a file as deleted in the database, you can use this line:
Code: Select all $aFileInfo = $d->Remove($aDoc['APP_DOC_UID'], $aDoc['DOC_VERSION']);
You probably want to execute this code after clicking on a submit button in a form. See this code example:
http://wiki.processmaker.com/3.0/Submit ... ancel_Case