0

I am trying to achieve this following scenario :

As file Object are getting posted through but in string format, how can i get file objects into php file.

Passed data:

Array (7)
0 {name: "title", value: "ABC"}
1 {name: "lat", value: "4.627044746156027"}
2 {name: "lng", value: "3.724853515625"}
3 {name: "area_id", value: "1"}
4 {name: "_token", value: "7G643pPBJxxEkfaXrYkZq7e3sBcdQjcmekoPVRAB"}
5 {name: "file[]", value: File}
6 {name: "file[]", value: File}

Returned data:

["[object File]", "[object File]"]

I need to parse the files into laravel but unable to get the file object values.

note: i want to achieve this without FormData.

following is the code to pass data:

function ajaxRequest(postUrl, method, postData) {
    postData.push({name: '_token', value: $('meta[name="csrf-token"]').attr('content')});

    if(files !== undefined) {
        $.each(files, function(i, file) {
            postData.push({name: 'file[]', value: file});
        });
    }

    console.log(postData);

    $.ajax({
        url: dataUrl + postUrl,
        method: method,
        data: postData,
        success: function(data) {
            console.log(data);
            // eval('toastr.' + data.class + '("' + data.message + '")');
            // window.setTimeout(function() { location.reload(); }, 2000)
        },
        error: function() {
            toastr.error("An error occured, please try again.");
        }
    });
}
Farrukh Ayyaz
  • 294
  • 1
  • 11

0 Answers0