There is a google map of api, where everyone can leave a mark, where information about missing animals will be displayed, I try to make it possible to upload photos, but so far without success.

Event with clicks on the map:

google.maps.event.addListener(map, 'rightclick', function(event) { var EditForm = '<p><div class="marker-edit">'+ '<form enctype="multipart/form-data" action="ajax-save.php" method="POST" name="SaveMarker" id="SaveMarker">'+ '<label for="pUpload"><input type="file" accept="image/*" name="pUpload" class="save-upload"></label>'+ '</form>'+ '</div></p><button name="save-marker" class="save-marker">'+saveMark+'</button>'; create_marker(event.latLng, info, EditForm, true, true, true, "#"); }); 

In the create_marker () function:

 var mUpload = $('input.save-upload')[0].files; save_marker(mUpload) 

In the save_marker () function

 var myData = new FormData(); myData.append ( 'file', mUpload); $.ajax({ type: "POST", url: "map_process.php", processData: false, contentType: false, data: myData, success:function(data){ var json = JSON.parse(data); 

In map_process.php

 $etc = var_dump($_FILES); die($etc); 

And var_dump shows that it is empty, I can not understand where I missed something, full javascript: jsfiddle

    1 answer 1

    You have form action = "ajax-save.php", maybe there is a problem.

    • Not in it, except for the file, other data is sent, with them everything is ok. - Alexander Reizan
    • Put before var myData = new FormData (); console.log (mUpload); shows [object FileList], then the file comes to the form, right? - Alexander Reizan
    • When I do this, I usually put an argument for FormData, for example, var myForm = $('input.SaveMarker')[0]; var myData = new FormData(myForm ); var myForm = $('input.SaveMarker')[0]; var myData = new FormData(myForm ); - Mae
    • If console.log worked, then it reached myData. As I understand it, you do not have an error in the request, but the data is not transmitted. It is necessary to look for the reason in the wrong data assignment. - Mae