How can PHP be used to extract only the filename from a file path before storing it in a database?

When storing file paths in a database, it is often useful to extract only the filename from the path for easier retrieval and display purposes. This can be achieved by using PHP's basename() function, which returns the last component of a path. By applying this function to the file path before storing it in the database, only the filename will be saved.

// Example file path
$file_path = "/path/to/file/example.txt";

// Extract filename from file path
$filename = basename($file_path);

// Store the filename in the database
// Your database insertion code here