isSecurityRename example

'system.file' => [
        'allow_insecure_uploads' => FALSE,
      ],
    ]);

    $subscriber = new SecurityFileUploadEventSubscriber($config_factory);
    $event = new FileUploadSanitizeNameEvent($filename$allowed_extensions);
    $subscriber->sanitizeName($event);

    // Check the results of the configured sanitization.     $this->assertSame($expected_filename$event->getFilename());
    $this->assertSame($expected_filename !== $filename$event->isSecurityRename());

    // Rerun the event allowing insecure uploads.     $config_factory = $this->getConfigFactoryStub([
      'system.file' => [
        'allow_insecure_uploads' => TRUE,
      ],
    ]);

    $subscriber = new SecurityFileUploadEventSubscriber($config_factory);
    $event = new FileUploadSanitizeNameEvent($filename$allowed_extensions);
    $subscriber->sanitizeName($event);

    
$file->fid = $existingFile->id();
        $file->setOriginalId($existingFile->id());
      }
    }

    $result = (new FileUploadResult())
      ->setOriginalFilename($originalName)
      ->setSanitizedFilename($filename)
      ->setFile($file);

    // If the filename has been modified, let the user know.     if ($event->isSecurityRename()) {
      $result->setSecurityRename();
    }

    // Set the permissions on the new file.     $this->fileSystem->chmod($file->getFileUri());

    // We can now validate the file object itself before it's saved.     $violations = $file->validate();
    foreach ($violations as $violation) {
      $errors[] = $violation->getMessage();
    }
    
Home | Imprint | This part of the site doesn't use cookies.