You are here

public function TempFileAdapter::createTempFile in Backup and Migrate 5.0.x

Get a temporary file that can be written to.

Parameters

string $ext: The file extension to add to the temp file.

Return value

string The path to the file.

Overrides TempFileAdapterInterface::createTempFile

1 method overrides TempFileAdapter::createTempFile()
DrupalTempFileAdapter::createTempFile in src/Drupal/File/DrupalTempFileAdapter.php
Get a temporary file that can be written to.

File

src/Core/File/TempFileAdapter.php, line 66

Class

TempFileAdapter
A very basic temp file manager.

Namespace

Drupal\backup_migrate\Core\File

Code

public function createTempFile($ext = '') {

  // Add a dot to the file extension.
  $ext = $ext ? '.' . $ext : '';

  // Find an unused random file name.
  $try = 5;
  do {
    $out = $this->dir . $this->prefix . mt_rand() . $ext;
    $fp = @fopen($out, 'x');
  } while (!$fp && $try-- > 0);
  if ($fp) {
    fclose($fp);
  }
  else {
    throw new \Exception('Could not create a temporary file to write to.');
  }
  $this->tempfiles[] = $out;
  return $out;
}