I use jQuery
, without plugin, to be able to upload files.
I'll illustrate in a very simplified way:
index.php
<script src="jquery.js"></script>
<script>
$(function()
{
$('form').submit(function(e)
{
e.preventDefault();
var formData = new FormData();
formData.append('image', $('#file').prop('files')[0]);
$.ajax({
url: 'upload.php',
data: formData,
type: 'post',
success: function(response)
{
console.log(response)
},
processData: false,
cache: false,
contentType: false
});
});
});
</script>
<form method="post" enctype="multipart/form-data">
<input type="file" id="file" />
<input type="submit" />
</form>
upload.php
if (move_uploaded_file($_FILES['image']['tmp_name'], $novo_nome)) {
echo json_encode($_FILES);
}
You need to send the data via post by Ajax and, in the form, set it to enctype="multipart / form-data"