What security concerns should be considered when handling file uploads in PHP forms?

When handling file uploads in PHP forms, it is essential to consider security concerns such as file type verification, file size limitations, and proper file storage location to prevent malicious uploads and potential security vulnerabilities.

// Check file type before uploading
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
if (!in_array($_FILES['file']['type'], $allowedTypes)) {
    die('Invalid file type.');
}

// Limit file size
$maxFileSize = 1000000; // 1MB
if ($_FILES['file']['size'] > $maxFileSize) {
    die('File size too large.');
}

// Store file in a secure location
$uploadPath = '/var/www/uploads/';
$targetFile = $uploadPath . basename($_FILES['file']['name']);
if (!move_uploaded_file($_FILES['file']['tmp_name'], $targetFile)) {
    die('Failed to upload file.');
}