I'm trying to upload without From, for image upload, but I can not.
html
<input id="avatar" type="file" name="avatar" />
<button id="btnOcorrenciaSalvar">Salvar</button>
Javascript code:
$("#btnOcorrenciaSalvar").click(function() {
event.preventDefault();
var form_data = new FormData();
nomeFoto = event.filename;
var file_data = $("#avatar").prop("files")[0];
form_data.append("file", file_data)
form_data.append("foto", nomeFoto)
$.ajax({
url: 'http://url.com.br/temp.php',
type: 'POST',
data: form_data,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (returndata) {
//$("#productFormOutput").html(returndata);
alert(form_data);
},
error: function () {
alert("error in ajax form submission");
}
});
return false;
});
PHP code to receive POST:
<?php
move_uploaded_file($_FILES["avatar"]["tmp_name"], "ocorrencias/" . $_POST["foto"]);
?>