0

I have used Jquery file picker plugin, and i tried to upload file using jquery ajax call with php..

HTML

<form >
   <input id="" data-label="Upload" class="form-control txtbx filepicker-custom"     name="media_src" type="file" placeholder="Pick Media src" multiple="" style="position: absolute; visibility: hidden;">

    <input type="text" name="src" class="form-control txtbx " placeholder="Ex: http://www.eventmagazine.co.uk/sky-broadband-launches/article/1424403">

<button type="button" class="btn btn-cls" id="addbtn">Submit</button>
</form>

<script>
        $(document).ready(function(){
            $('#addbtn').click(function(){

                var data1 = JSON.stringify( $('form').serializeArray() );

                $.ajax({
                    method: "POST",
                    url: "addToDB.php",
                    //dataType: "json",
                    //contentType: false,
                    //processData: false,
                    data: {EData: data1},
                    success: function(reqResult){
                        alert(reqResult);
                    }
                }); 

            });
        });
    </script>

addToDB.php

if(isset($_POST['EData'])){

    $FormDataArr = json_decode(stripslashes($_POST['EData']));

    file_put_contents("FORMDATA.txt", print_r($FormDataArr, true));

    echo 1;
}

FORMDATA.txt

Array
(
    [0] => stdClass Object
        (
            [name] => src
            [value] => www.sample.com
        )
)

In FORMDATA.txt file i got only one filed (name and value pair), so how to handle File upload action in php in this sutiation.. How to upload multiple file in jquery ajax ?

Balakumar B
  • 770
  • 5
  • 17
  • 41

0 Answers0