First of all, I got this enctype="multipart/form-data"
in my form tag.
When I send a data as a text, it proceeds and give me data.
<input type="text" class="form-control" name="attachment">
But when I change the type as "file", it don't send a data.
<input type="file" class="form-control" name="attachment">
Here is my HTML File:
<form id="form_attachment" method="POST" enctype="multipart/form-data">
<input type="hidden" name="employee_number" value="<?= $_GET[md5('employee_number')] ?>">
<label class="bmd-label-floating">Choose Attachment</label>
<input type="file" class="form-control" name="attachment">
<label class="bmd-label-floating">Remarks</label>
<textarea name="remarks" rows="5" class="form-control"></textarea>
<input type="submit" id="btn_attachment" value="Insert" class="btn btn-info" style="float:right" /><br><br>
</form>
AJAX:
$('#form_attachment').on("submit", function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "../ajax/insert_attachment.php",
data: $("#form_attachment").serialize(),
beforeSend: function() {
$('#btn_attachment').val("Updating");
},
success: function(response) {
$('#form_attachment')[0].reset();
$('#btn_attachment').val("Update");
$('#modal_attachment').modal('hide');
// $('#div_attachment').html(response);
md.onboarding('bottom', 'right', response);
}
});
e.preventDefault();
});
PHP:
$employee_number = $_POST['employee_number'];
$attachment = $_FILES["attachment"]["name"];
$attachment_tmp = $_FILES['attachment']['tmp_name'];
$remarks = $_POST['remarks'];
It gives me this error:
NOTICE: Undefined index: attachment in
C:\XAMPP\HTDOCS\AJAX\INSERT_ATTACHMENT.PHP on line 6
NOTICE: Undefined index: attachment in
C:\XAMPP\HTDOCS\AJAX\INSERT_ATTACHMENT.PHP on line 7