How to pass file input from javascript to PHP in OctoberCMS

Here is a demonstration of the issue:

HTML

<form data-request="onSubmit" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileUpload" id="fileUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

PHP

function onSubmit()
{
    echo $_FILES["fileUpload"]["name"];
}

This code always outputs

“Undefined index: fileUpload”

Which clearly means that PHP isn’t able to access the data since the index that should contain a file is undefined. How would I be able to pass a file input by the user into PHP?

Solutions can use jQuery if necessary.

P.S. I already tried the solution here. It did not work.


Source: stackoverflow-php