You are here

public function FileMetadata::copyUriToTemp in File metadata manager 8

Same name and namespace in other branches
  1. 8.2 src/FileMetadata.php \Drupal\file_mdm\FileMetadata::copyUriToTemp()

Copies the file at URI to a local temporary file.

Parameters

string $temp_uri: (optional) a URI to a temporary file. If NULL, a temp URI will be defined by the operation. Defaults to NULL.

Return value

bool TRUE if the file was copied successfully, FALSE otherwise.

Overrides FileMetadataInterface::copyUriToTemp

File

src/FileMetadata.php, line 118

Class

FileMetadata
A file metadata object.

Namespace

Drupal\file_mdm

Code

public function copyUriToTemp($temp_uri = NULL) {
  if ($temp_uri === NULL) {
    $temp_uri = $this->fileSystem
      ->tempnam('temporary://', 'file_mdm_');
    $this->fileSystem
      ->unlink($temp_uri);
    $temp_uri .= '.' . pathinfo($this
      ->getUri(), PATHINFO_EXTENSION);
  }
  if ($temp_path = file_unmanaged_copy($this
    ->getUri(), $this->fileSystem
    ->realpath($temp_uri), FILE_EXISTS_REPLACE)) {
    $this
      ->setLocalTempPath($temp_path);
  }
  return (bool) $temp_path;
}