0

So basically I have a bootstrap modal pop up in which I want to upload a csv via jquery/ajax so I can parse through using PHP.

I'm using laravel and this is currently my code:

Modal:

<div class="modal fade" id="uploadRecipientListModal" tabindex="-1" role="dialog"  aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title text-center">Add Recipient List</h5>
            </div>
            <div class="modal-body">
                 <form enctype="multipart/form-data" id="modal_form_id"  method="POST" >
                    <input type="file" name="documents">
                 </form>

                 <button id="uploadRecipientSubmit1">
            </div>
        </div>
    </div>
</div>

JS:

$( "#uploadRecipientSubmit1" ).click(function() {
    var postData = new FormData($("#modal_form_id")[0]);

    $.ajax({
            type:'POST',
            url:'recipient/upload-contact-list',
            processData: false,
            contentType: false,
            data : postData,
            success:function(data){
              console.log("File Uploaded" + data);
            },
            error:function(data){
              console.log("nope");
            }

        });       


});

Controller PHP:

public function uploadContactList(Request $request)
{
    if(\Illuminate\Support\Facades\Input::hasFile('documents')) {

       echo "Good";

    }
    else
    {
        echo "bad";
    }
}

Routes:

Route::post('/recipient/upload-contact-list', 'RecipientController@uploadContactList')->name('upload.contact.list');

Output in console:

File Uploadedbad

I just cant get access to the csv file i'm trying to upload so I can parse through it and upload the rows to the db.

I've been struggling on this one for a while and tried multiple different things but cant get this working, can someone tell me where I'm going wrong?

Thanks

TEster
  • 191
  • 2
  • 4
  • 19

0 Answers0