public function TempFileAdapter::createTempFile in Backup and Migrate 8.4
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/
File/ DrupalTempFileAdapter.php - Get a temporary file that can be written to.
File
- lib/
backup_migrate_core/ src/ File/ TempFileAdapter.php, line 60
Class
- TempFileAdapter
- Provides a very basic temp file manager which assumes read/write access to a local temp directory.
Namespace
BackupMigrate\Core\FileCode
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;
}