This question already has an answer here:
I'm having trouble getting the file from my input type file.
I have tried var file = document.getElementById('filex').value;
and var file = $('#filex').val;
but when I try to send the request it sends as 'undefined'.
My form looks like this:
<form id="form" method="post" enctype="multipart/form-data>
<input type="file" name="file" id="filex"/>
<input type="button" value="Upload" id="submit/>
</form>
My Javascript currently looks like this:
function shipOff() {
var file = document.getElementById('filex').value;
var fileName = document.getElementById('filex').value.toString();
console.log("Sending " + fileName);
$.post('uploader.php',
{
data: file,
name: fileName,
cache: false,
processData: false
},
function(returned){ console.log(returned); }
);
}
And lastly the short PHP file:
<?php
if($_FILES['file']['size'] > 0)
{
echo "Success!";
}else{
echo "No file";
}
?>
Aucun commentaire:
Enregistrer un commentaire