What are the best practices for handling file input in PHP forms, especially when dealing with directory paths?

When handling file input in PHP forms, it is important to ensure that the file paths are sanitized and validated to prevent security vulnerabilities such as directory traversal attacks. One way to do this is by using the `realpath()` function to get the absolute path of the file. Additionally, it is recommended to store uploaded files in a secure directory outside of the web root to prevent direct access to sensitive files.

// Get the absolute path of the uploaded file
$uploadedFilePath = realpath($_FILES['file']['tmp_name']);

// Define a secure directory to store uploaded files
$uploadDirectory = '/path/to/uploaded/files/';

// Move the uploaded file to the secure directory
move_uploaded_file($_FILES['file']['tmp_name'], $uploadDirectory . $_FILES['file']['name']);