What are the potential pitfalls of not moving or renaming temporary files in PHP scripts?

If temporary files are not moved or renamed in PHP scripts, it can lead to security vulnerabilities such as directory traversal attacks or information disclosure. It is important to always move or rename temporary files to a secure location before processing them to prevent unauthorized access.

// Example of moving and renaming a temporary file in PHP
$tempFile = $_FILES['file']['tmp_name'];
$targetFile = 'uploads/' . basename($_FILES['file']['name']);

if (move_uploaded_file($tempFile, $targetFile)) {
    echo "File uploaded successfully.";
} else {
    echo "Error uploading file.";
}