In what ways can PHP developers ensure that client-side files are properly accessed and processed in server-side scripts for email attachments?

When working with email attachments in PHP, developers need to ensure that client-side files are properly accessed and processed in server-side scripts. One way to achieve this is by using the $_FILES superglobal to handle file uploads securely and efficiently.

// Check if the file was uploaded successfully
if ($_FILES['attachment']['error'] === UPLOAD_ERR_OK) {
    // Specify the directory where the file will be saved
    $uploadDir = 'uploads/';
    $uploadFile = $uploadDir . basename($_FILES['attachment']['name']);

    // Move the uploaded file to the specified directory
    if (move_uploaded_file($_FILES['attachment']['tmp_name'], $uploadFile)) {
        echo 'File is valid, and was successfully uploaded.';
    } else {
        echo 'Possible file upload attack!';
    }
} else {
    echo 'File upload error: ' . $_FILES['attachment']['error'];
}