How can PHP scripts be optimized for performance when handling large numbers of file uploads and directory creations?

When handling large numbers of file uploads and directory creations in PHP, it is important to optimize the code for performance by minimizing unnecessary operations and improving efficiency. One way to achieve this is by using functions like `move_uploaded_file()` instead of manually copying files, and `mkdir()` instead of creating directories recursively. Additionally, using proper error handling and validation can help prevent unnecessary processing and improve overall performance.

// Example code snippet for optimizing file uploads and directory creations
// Move uploaded files to a specific directory
$uploadDir = 'uploads/';
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {
    $uploadFile = $uploadDir . basename($_FILES['files']['name'][$key]);
    move_uploaded_file($tmp_name, $uploadFile);
}

// Create directories if they do not exist
$directory = 'new_directory/';
if (!file_exists($directory) && !is_dir($directory)) {
    mkdir($directory);
}