How can I ensure that the uploaded file is stored with the correct file extension in PHP?
When uploading a file in PHP, the file extension can sometimes be missing or incorrect, which can cause issues when accessing or using the file later on. To ensure that the uploaded file is stored with the correct file extension, you can use the `pathinfo()` function to extract the file extension from the uploaded file name and then append it to the destination file path.
// Get the file extension from the uploaded file name
$uploadedFileName = $_FILES['file']['name'];
$extension = pathinfo($uploadedFileName, PATHINFO_EXTENSION);
// Set the destination directory and file name with the correct file extension
$destination = 'uploads/' . uniqid() . '.' . $extension;
// Move the uploaded file to the destination with the correct file extension
move_uploaded_file($_FILES['file']['tmp_name'], $destination);