use TYPO3\CMS\Core\Utility\GeneralUtility; $sourceFile = 'typo3conf/ext/myextension/Resources/Public/Images/myfile.jpg'; $targetFile = 'typo3conf/ext/myextension/Resources/Public/Images/newfile.jpg'; if (file_exists($sourceFile)) { GeneralUtility::upload_copy_move($sourceFile, $targetFile); }
use TYPO3\CMS\Core\Utility\GeneralUtility; $sourceFile = 'typo3conf/ext/myextension/Resources/Public/Images/myfile.jpg'; $targetFile = 'typo3conf/ext/myextension/Resources/Public/UploadedImages/newfile.jpg'; if (file_exists($sourceFile)) { GeneralUtility::upload_copy_move($sourceFile, $targetFile, $createIntermediateDirs = FALSE, $overrideExistingTarget = TRUE); }In this example, we're using the same upload_copy_move method to move the file at $sourceFile to $targetFile. We set the $createIntermediateDirs parameter to FALSE because the target directory already exists. We also set the $overrideExistingTarget parameter to TRUE, which means if there's already a file at the target location with the same name, it will be overwritten. Overall, the GeneralUtility upload_copy_move method is a powerful and flexible tool for managing files in TYPO3 CMS.