| 7 file.inc | drupal_basename($uri, $suffix = NULL) |
| 8 file.inc | drupal_basename($uri, $suffix = NULL) |
Gets the filename from a given path.
PHP's basename() does not properly support streams or filenames beginning with a non-US-ASCII character.
See also
http://bugs.php.net/bug.php?id=37738
basename()
Related topics
36 calls to drupal_basename()
- color_scheme_form_submit in core/
modules/ color/ color.module - Form submission handler for color_scheme_form().
- drupal_add_css in core/
includes/ common.inc - Adds a cascading stylesheet to the stylesheet queue.
- drupal_tempnam in core/
includes/ file.inc - Creates a file with a unique filename in the specified directory.
- FileManagedTestBase::createFile in core/
modules/ file/ lib/ Drupal/ file/ Tests/ FileManagedTestBase.php - Create a file and save it to the files table and assert that it occurs correctly.
- FileStorageController::create in core/
modules/ file/ lib/ Drupal/ file/ FileStorageController.php - Overrides Drupal\Core\Entity\DatabaseStorageController::create().
File
- core/
includes/ file.inc, line 1691 - API for handling file uploads and server file management.
Code
function drupal_basename($uri, $suffix = NULL) {
$separators = '/';
if (DIRECTORY_SEPARATOR != '/') {
// For Windows OS add special separator.
$separators .= DIRECTORY_SEPARATOR;
}
// Remove right-most slashes when $uri points to directory.
$uri = rtrim($uri, $separators);
// Returns the trailing part of the $uri starting after one of the directory
// separators.
$filename = preg_match('@[^' . preg_quote($separators, '@') . ']+$@', $uri, $matches) ? $matches[0] : '';
// Cuts off a suffix from the filename.
if ($suffix) {
$filename = preg_replace('@' . preg_quote($suffix, '@') . '$@', '', $filename);
}
return $filename;
}