'How to upload & pass variables to the same php file

I try uploading a text file from client desktop to a server. A web page is built on js like this:

const usunDane = document.getElementById('cbxUsunDane').checked;
const nadpiszDane = document.getElementById('cbxNadpiszDane').checked;

formData.append("file", selectedFile);
formData.append("usunDane", usunDane);
formData.append("nadpiszDane", nadpiszDane);

   await fetch('php/produktyUpload.php', {
     method: "POST", 
     body: formData
   });

I added usunDane and nadpiszDane hoping to pass it into produktyUpload.php file, however I do not know how to properly read it. I tried this:

if ($_FILES['nadpiszDane']=="true") {
    error_log("UPDATE ", 3, "/var/www/html/errors.log");
} else {
    error_log("INSERT ", 3, "/var/www/html/errors.log");
}

... but this does not work.

When I look at the browser I can see that both variables are passed to php file... * Content-Disposition: form-data; name="usunDane" true

Content-Disposition: form-data; name="nadpiszDane" true *

Could someone please advice on how to pass/read these variables?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source