Issue Task Closed

#96780rename file in server

razieh zivaralam 02/08/22, 09:33 updated 05/03/22, 11:41

Description

hi evreybody
how can i rename a file in server? I wanted to change an uploaded file with another file… i changed the contet of the old one into new file with below code:

$fileReference = $this->resourceFactory->getFileReferenceObject( $id);
$file=$fileReference->getOriginalFile();
$file->setContents($content);

i see the new file now in frontend but i want to change the name of file too? how can i do it?

i dont wanted to delete the file and add a new file beacuse i dont want to increase id in sys-table and etc…..

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 5

  1. razieh zivaralam changed subject rename folder rename file in server 02/08/22, 09:35

  2. Oliver Hader commented 02/08/22, 11:11

    $file->setContents($content); just replaces the (inner) contents of a file, but not the name.
    The ResourceStorage is capable of dealing with how and where files are stored – including renaming.

    $file->getStorage()->renameFile($file, 'the-new-image-name.png')

    see https://github.com/TYPO3/typo3/blob/bc15ad4b24a3c76087a2aa1172d44cb84fe0569c/typo3/sysext/core/Classes/Resource/ResourceStorage.php#L2029-L2038

  3. Oliver Hader changed tracker Feature Task status New Needs Feedback Tags pending-close TYPO3 Version 11 02/08/22, 11:11

  4. Christian Kuhn commented and changed status Needs Feedback Closed 02/19/22, 17:30

    hey. i hope it’s ok to close here since that was more an API question than a core issue.

  5. razieh zivaralam commented 05/03/22, 11:41

    thanks