Silverstripe Version: 4.2
Question: How to store a File
When I use $file->setFromString it creates a FileObject but:
- Filename in DB is null
- When I Upload a second File with the same Name it creates a new File Object and it’s naming it v2,v3 ect. but it points to the SAME F*CKING FILE there is only one File on Servers Disk.
The Documentation here: https://docs.silverstripe.org/en/4/developer_guides/files/file_management/
is outdated. It says “The conflict resolution to use can be passed into the third parameter of the above methods” third parameter is a hash.
public function submit($data, $form){
if ( !$data["Dokument"]["error"] > 0 ) {
$image = $data['Dokument'];
$content = file_get_contents($image['tmp_name']);
$file = File::create();
$file->setFromString($content, $image['name']);
$file->ParentID = 95263;
$file->write();