[TYPO3-mvc] FAL - saving file from external source

Michal Cygankiewicz mc at amtsolution.pl
Mon Jun 20 11:48:14 CEST 2016


I want to save file from external source by FAL.

This is my code in TYPO3 6.2:

$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
$storage = current($storageRepository->findAll());
$fileObject = $storage->createFile($data[$key][1]['name'], $storage->getRootLevelFolder());
$storage->setFileContents($fileObject, file_get_contents($data[$key][1]['publicUrl']));

This works but if the filename already exists on the server in given path - the existing file is beeing overwritten with new one which is not desired behaviour. I want new file to be renemaed automatically if file with same name already exists on the server. Can it be handled by TYPO3?

I also look into addFile function http://api.typo3.org/typo3cms/62/html/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_resource_1_1_resource_storage.html#a331138343dad530cbb3940644fadcb1b but it requires the file to be saved already on the server which I would like to not handle by my own if possible.


More information about the TYPO3-project-typo3v4mvc mailing list