0

I am posting a form to itself with jquery which has a file upload in it. I cannot get the file name, i keep getting userfile is not set... when trying to capture the file name

$(document).ready(function(){
$("#chmail").validate({
debug: false,
submitHandler: function(form) {
$.post('new_mail.php', $("#chmail").serialize(), function(data) {
$('#mainBody').html(data);
$("#mainBody").find("script").each(function(i) {
eval($(this).text());
});
});
}
});
});

if (isset($_FILES["userfile"]["name"])) {
echo $_FILES["userfile"]["name"];
}


<form method="post" action="" id="chmail" name="chmail" enctype="multipart/form-data">
<input type="file" id="userfile" name="userfile" />
<button type="submit" value="Send">
</form>

Any help would be appreciated :) Many thanks

Patdundee
  • 161
  • 2
  • 10

1 Answers1

0

This works fine

St up the iframe on your page. In the form set the target as the iframe and set the action to call the script for your uploaded files. No other scripts needed

<iframe name="my-iframe" frameborder="0" scrolling="no"></iframe>


<form method="post" id="chmail" name="chmail" enctype="multipart/form-data" action="process_mail.php" target="my-iframe">
Patdundee
  • 161
  • 2
  • 10