[TYPO3-project-formidable] Delete button in Lister that delete the record and his relative file

Ian Solo ian at webian.it
Tue May 13 08:49:52 CEST 2008


Hello,
following this thread:
http://lists.netfielders.de/pipermail/typo3-project-formidable/2007-December/000812.html

I added a delete button [1] that:
1. get the full server path of the file of the record
2. delete the file
3. delete the record

it works (atm it's only tested on a windows xp machine), but I'm 
wondering if there is a better way to do it.

Thank you for any hint!
ian

[1] Here follows the xml of the delete button:
***********************************************************************************
<column type="renderlet:BUTTON" name="btn-del" listHeader="" 
label="Delete" class="delete">
	<onclick runat="server" params="uid, image" confirm="Are you sure you 
want to delete this image?" when="start" >
		<userobj>
			<php><![CDATA[
				$aParams = func_get_args();
				$iImage = $aParams[1]["image"];
				// $iImage now has the filename
				$oFileTool = t3lib_div::makeInstance("t3lib_basicFileFunctions");
				$sTargetDir = 'uploads/tx_iangallery/';
				$sTargetDir = t3lib_div::fixWindowsFilePath(
					$oFileTool->slashPath(
						$oFileTool->rmDoubleSlash(
							$sTargetDir
						)
					)
				);
				$sPath = $sTargetDir.$iImage;
				$sPath = tx_ameosformidable::toRelPath($sPath);
				if(file_exists($sPath) && is_dir($sPath) && ($sPath{(strlen($sPath) 
- 1)} !== "/")) {
					$sPath .= "/";
				}
				$sPath = 
tx_ameosformidable::_removeEndingSlash(t3lib_div::getIndpEnv("TYPO3_DOCUMENT_ROOT")) 
. "/" .  tx_ameosformidable::_removeStartingSlash($sPath);
				// $sPath now has the full server path of the file
				
				// delete the file
				@unlink($sPath);
				
				// delete the record
				$iUid = $aParams[1]["uid"];
				$GLOBALS["TYPO3_DB"]->exec_DELETEquery( "tx_iangallery_gallery", 
"uid='" . $iUid . "'" );
			]]></php>
		</userobj>
	</onclick>
</column>
***********************************************************************************


More information about the TYPO3-project-formidable mailing list