How can the use of is_uploaded_file and is_writeable functions be optimized for successful file uploads in PHP?

To optimize file uploads in PHP, it is important to use the is_uploaded_file function to check if the file was uploaded via HTTP POST and the is_writeable function to ensure that the destination directory is writable. By using these functions, you can prevent unauthorized uploads and ensure that the file can be successfully written to the server.

if (is_uploaded_file($_FILES['file']['tmp_name']) && is_writeable('uploads/')) {
    move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $_FILES['file']['name']);
    echo 'File uploaded successfully.';
} else {
    echo 'Failed to upload file.';
}