You are here

protected function DropzoneJsUploadSave::renameExecutableExtensions in DropzoneJS 8.2

Same name and namespace in other branches
  1. 8 src/DropzoneJsUploadSave.php \Drupal\dropzonejs\DropzoneJsUploadSave::renameExecutableExtensions()

Rename potentially executable files.

Parameters

\Drupal\file\FileInterface $file: The file entity object.

Return value

bool Whether the file was renamed or not.

1 call to DropzoneJsUploadSave::renameExecutableExtensions()
DropzoneJsUploadSave::createFile in src/DropzoneJsUploadSave.php
Creates a file entity form an uploaded file.

File

src/DropzoneJsUploadSave.php, line 218

Class

DropzoneJsUploadSave
A service that saves files uploaded by the dropzonejs element as files.

Namespace

Drupal\dropzonejs

Code

protected function renameExecutableExtensions(FileInterface $file) {
  if (!$this->configFactory
    ->get('system.file')
    ->get('allow_insecure_uploads') && preg_match('/\\.(php|pl|py|cgi|asp|js)(\\.|$)/i', $file
    ->getFilename()) && substr($file
    ->getFilename(), -4) != '.txt') {
    $file
      ->setMimeType('text/plain');

    // The destination filename will also later be used to create the URI.
    $file
      ->setFilename($file
      ->getFilename() . '.txt');
    return TRUE;
  }
  return FALSE;
}