lundi 5 octobre 2020

Upload AJAX with input text and input file in PHP

In the JS site in have to send an ajax containing an input file to upload AND input texts

var formdata = new FormData();
    formdata.append("id",$('#id').val());
    formdata.append("upload_url",$('#upload_url').val());
    formdata.append("type",$('#type').val());
    formdata.append("file",$('#upload').prop('files')[0]);
    formdata.append("label",$('#label').val());
    formdata.append("filter_from",$('#filter_from').val());
    formdata.append("filter_to",$('#filter_to').val());
    formdata.append("zone_geographique",$('#zone_geographique').val());
    formdata.append("actif",$('#actif').val());
    formdata.append("leafs",$('#affectedLeafs').val());
    $.ajax({
        url: 'form.php?action=formation_save',
        data: formdata,
        processData: false,
        contentType: false,
        type: 'POST',
        success: function() {
            $('.formationSection > div').slideToggle();
        }
    });

But when , in the PHP side in the formation_save file, I do a $_POST, PHP returns me NULL.

and when I do also a file_get_contents("php://input"); PHP returns also me NULL

But Why ? How to make it working ?

PHP code

<?php

    $postValues = $_POST;
    $phpinput = file_get_contents("php://input");
    
    var_dump($postValues);var_dump($phpinput);



Aucun commentaire:

Enregistrer un commentaire