Overwrite upload file

In version 2025.2,
All uploaded files with the same name will be deleted and replaced with new ones.

bool $overWrite argument
in saveToFile function
in file : HttpUpload.php :

public function saveToFile(string $newFileName, **bool $overWrite**, int $idx = -1): bool

In phpfn.php :

In the SaveUploadFiles function

it is set to True directly
and does not allow renaming

function SaveUploadFiles(DbField $fld, ?string $fileNames, bool $resize): bool
....
$fld->Upload->saveToFile($newFile, **true**, $i); // Save

Is this the case in my version or did I change something?

File with same file name in the same upload folder usually is the old file of the same field. When the record is updated, the files are also updated. (Other fields uploading file with the same file name to the same folder will get new file name index appended to the file name.)

Suppose a user has already saved a file and that file is used in other parts.

And some time later another user, without knowing the names of the previous files (which they don’t need to know), creates another file with the same name in another row…

The previous file of the first user is deleted. While it contained other information!

I don’t think this is correct.

You may determine such cases yourself according to your own logic and change the file name by Row_Inserting/Updating server events.

1 Like

Thank you for your guidance :slightly_smiling_face: