I'm using ajax/php to load files but I don't understand how to add other variable than the file in the ajax function.
HTML:
<html>
    <body>      
        Select image to upload:     
        <input type="file" name="fileToUpload" id="fileToUpload">       
        <button onclick="loadNewPicture('tomato')" id="upload">Upload</button>
    </body>
</html>
JAVASCRIPT:
function loadNewPicture(vegetable)
    {
        var file_data = $('#fileToUpload').prop('files')[0];     
        var form_data = new FormData();                                 
        form_data.append('file', file_data);
        $.ajax(
        {
            url: 'TEST.php',
            dataType: 'text',
            cache: false,
            contentType: false,
            processData: false,
            data: form_data + '&vegetable =' + vegetable ,                                               
            type: 'post',
         });
    }
PHP:
<?php
    if ( 0 < $_FILES['file']['error'] ) 
    {
        echo 'Error: ' . $_FILES['file']['error'] . '<br>';
    }
    else 
    {
        $vegetable = ($_POST["vegetable"]);
        move_uploaded_file($_FILES['file']['tmp_name'], 'image/test/' . $_FILES['file']['name']);
    }
?>
Of course, it does not work saying "Undefined index: file" Any idea how could I do?
 
     
    