You are here

protected function RemotePostWebformHandler::getRequestFileData in Webform 6.x

Get request file data.

Parameters

int $fid: A file id.

string|null $prefix: A prefix to prepended to data.

Return value

array An associative array containing file data (name, uri, mime, and data).

1 call to RemotePostWebformHandler::getRequestFileData()
RemotePostWebformHandler::getRequestData in src/Plugin/WebformHandler/RemotePostWebformHandler.php
Get a webform submission's request data.

File

src/Plugin/WebformHandler/RemotePostWebformHandler.php, line 770

Class

RemotePostWebformHandler
Webform submission remote post handler.

Namespace

Drupal\webform\Plugin\WebformHandler

Code

protected function getRequestFileData($fid, $prefix = '') {

  /** @var \Drupal\file\FileInterface $file */
  $file = File::load($fid);
  if (!$file) {
    return [];
  }
  $data = [];
  $data[$prefix . 'id'] = (int) $file
    ->id();
  $data[$prefix . 'name'] = $file
    ->getFilename();
  $data[$prefix . 'uri'] = $file
    ->getFileUri();
  $data[$prefix . 'mime'] = $file
    ->getMimeType();
  $data[$prefix . 'uuid'] = $file
    ->uuid();
  if ($this->configuration['file_data']) {
    $data[$prefix . 'data'] = base64_encode(file_get_contents($file
      ->getFileUri()));
  }
  return $data;
}