Actions
Task #96780
closedrename file in server
Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2022-02-08
Due date:
% Done:
0%
Estimated time:
TYPO3 Version:
11
PHP Version:
Tags:
pending-close
Complexity:
Sprint Focus:
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.....
Updated by razieh zivaralam almost 3 years ago
- Subject changed from rename folder to rename file in server
Updated by Oliver Hader almost 3 years ago
$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')
Updated by Oliver Hader almost 3 years ago
- Tracker changed from Feature to Task
- Status changed from New to Needs Feedback
- Tags set to pending-close
- TYPO3 Version set to 11
Updated by Christian Kuhn almost 3 years ago
- Status changed from Needs Feedback to Closed
hey. i hope it's ok to close here since that was more an API question than a core issue.
Actions