예제 #1
0
 /**
  * Rename potentially executable files.
  *
  * @param \Drupal\file\FileInterface $file
  *   The file entity object.
  *
  * @return bool
  *   Whether the file was renamed or not.
  */
 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;
 }