22 November 2016

Snippet shows you how to get filename from a path in PHP. Filename and extension separately. Can be used for extending filenames with timestamp or anything.

Source code viewer
  1. $bg = pathinfo($path);
  2.  
  3. // Filename and extension separately, useful for extending filenames.
  4. echo $bg['filename'] . '.' . $bg['extension'];
  5.  
  6. // Full filename.
  7. echo $bg['basename'];
  8.  
Programming Language: PHP