Project

General

Profile

Actions

Task #96780

closed

rename file in server

Added by razieh zivaralam almost 3 years ago. Updated over 2 years ago.

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.....

Actions #1

Updated by razieh zivaralam almost 3 years ago

  • Subject changed from rename folder to rename file in server
Actions #2

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')

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

Actions #3

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
Actions #4

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 #5

Updated by razieh zivaralam over 2 years ago

thanks

Actions

Also available in: Atom PDF