What is the purpose of using basename() function in PHP and how is it used in the provided code snippet?

The purpose of using the basename() function in PHP is to extract the filename component from a given path. In the provided code snippet, the basename() function is used to extract the filename of the uploaded file from its full path. This can be useful when you only need the filename for further processing or display.

// Get the basename of the uploaded file
$filename = basename($_FILES["fileToUpload"]["name"]);

// Display the extracted filename
echo "Uploaded file: " . $filename;