I use the jQuery
, no plugin, so you can upload files.
I will 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);
}
Data must be sent via post by Ajax and, in the form, configure it as enctype="Multipart/form-data"
There is also a way to upload or post, without refresh, through an iframe that in the case is placed as target. Behold
– Wallace Maxters