What are the potential pitfalls of using $_FILES['file_name']['name1'] and $_FILES['folder_name']['name2'] in PHP for file uploads?

Potential pitfalls of using $_FILES['file_name']['name1'] and $_FILES['folder_name']['name2'] for file uploads include vulnerability to file path manipulation attacks and confusion in handling multiple file uploads. To solve this issue, it's recommended to use unique file names and store uploaded files in a secure directory.

// Generate a unique file name
$uniqueFileName = uniqid() . '_' . $_FILES['file_name']['name1'];

// Specify the secure directory to store uploaded files
$uploadDirectory = 'uploads/';

// Move the uploaded file to the secure directory with the unique file name
move_uploaded_file($_FILES['file_name']['tmp_name1'], $uploadDirectory . $uniqueFileName);