1

How to remove the date behind a asset filename or prevent add a date behind the filename? I'll have a plugin that's modifies an existing pdf with SETA SIGN. To do so I'm copy the current asset, modify it in the temp folder, unlink original, copy modified file and unlink the temp file. I tried to rename the file (with $rename) but still the date is added behind the filename. I'll found something with avoidFilenameConflicts but as far as I'll see this is for new assets not for moving or renaming assets.

$assetFilePath = $asset->getVolume()->getRootPath() . DIRECTORY_SEPARATOR . $asset->getPath();
....
        unlink($assetFilePath);
        copy($tempPath . DIRECTORY_SEPARATOR . $asset->filename, $assetFilePath);
        unlink($tempPath . DIRECTORY_SEPARATOR . $asset->filename);

...
$newFileName = 'bla.pdf';
$rename = Craft::$app->assets->moveAsset($asset,$asset->getFolder(),$newFileName);

bla.pdf becomes bla_2021-03-26-124307.pdf but I'll want just 'bla.pdf'.

1 Answer 1

1

Try using replaceAssetFile(), something like this (untested):

$rename = Craft::$app->assets->replaceAssetFile($asset->id,$asset->getFolder(),$newFileName);
1
  • Thanx for your reply, unfortunately same behavior. Commented Mar 31, 2021 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.