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

Frans Saris franssaris at gmail.com
Mon Jun 20 13:01:55 CEST 2016


Hi,

Create a temp file to save your remote file and use storage->addFile then
you have a option to rename the file when it already exists.

Gr. Frans

Op ma 20 jun. 2016 11:50 schreef Michal Cygankiewicz <mc at amtsolution.pl>:

> 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.
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>


More information about the TYPO3-project-typo3v4mvc mailing list