function Resource::_destination in D7 Media 6
Create a new name for a resource by appending a number if a resource exists at $destination.
2 calls to Resource::_destination()
- Resource::copy in resource/
resource.module - Create a copy a Resource.
- Resource::move in resource/
resource.module - Move a Resource.
File
- resource/
resource.module, line 158 - Resource API for Drupal, a replacement for files.
Class
- Resource
- Base Resource class.
Code
function _destination($destination, $replace = FILE_EXISTS_RENAME) {
if ($replace & FILE_EXISTS_REPLACE) {
return true;
}
if (!file_exists($destination)) {
return $destination;
}
if ($replace & FILE_EXISTS_ERROR) {
return FALSE;
}
$streamdir = dirname($destination);
$basename = basename($destination);
// Destination file already exists, generate an alternative.
$pos = strrpos($basename, '.');
if ($pos !== FALSE) {
$name = substr($basename, 0, $pos);
$ext = substr($basename, $pos);
}
else {
$name = $basename;
$ext = '';
}
$counter = 0;
do {
$destination = $streamdir . '/' . $name . '_' . $counter++ . $ext;
} while (file_exists($destination));
return $destination;
}