drupal_tempnam

Versions
7
drupal_tempnam($directory, $prefix)

Creates a file with a unique filename in the specified directory.

PHP's tempnam() does not return a URI like we want. This function will return a URI if given a URI, or it will return a filepath if given a filepath.

Compatibility: normal paths and stream wrappers.

See also

http://drupal.org/node/515192

See also

tempnam()

Parameters

$directory The directory where the temporary filename will be created.

$prefix The prefix of the generated temporary filename. Note: Windows uses only the first three characters of prefix.

Return value

The new temporary fillename, or FALSE on failure.

Related topics

▾ 1 function calls drupal_tempnam()

file_unmanaged_save_data in includes/file.inc
Save a string to the specified destination without calling any hooks or making any changes to the database.

Code

includes/file.inc, line 1900

<?php
function drupal_tempnam($directory, $prefix) {
 	$scheme = file_uri_scheme($directory);

  if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
    $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);

    if ($filename = tempnam($wrapper->getDirectoryPath(), $prefix)) {
      return $scheme . '://' . basename($filename);
    }
    else {
      return FALSE;
    }
  }
  else {
    // Handle as a normal tempnam() call.
    return tempnam($directory, $prefix);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.