I'm extremely confused by this. I have a form in which a user has the option to upload a resume... easy enough.
Unfortunately, every time I try to validate the file, I keep getting an 'Undefined Index' error, meaning the $_FILES[]
array is empty. I have upped my upload_max_filesize
& post_max_size
and ensured file uploads were turned on in my php.ini file and restarted apache but still the array returns empty.
Here is my form HTML:
<form enctype="multipart/form-data" class="form-horizontal" id="contact-form" name="contact-form" action="/includes/mail/" method="post">
<div id="resume-input" class="form-group">
<label class="control-label col-sm-2">Upload Resume</label>
<div class="col-sm-10">
<input type="file" name="resume" id="resume-file" class="form-control" />
</div>
</div>
</form>
and here is the PHP checking for the file:
if(!isset($_FILES['resume'])) {
echo "<span class='error'>Please upload your resume.</span><br />";
return false;
} else {
// Validate uploaded file
$fileName = $_FILES['resume']['name']; // file name
$fileExt = substr($fileName, strrpos($fileName, '.') + 1); // file extension
$fileSize = $_FILES['resume']['size']/1024; // size in KBs
$filePath = $_FILES['resume']['tmp_path']; // file path
}
Obviously this isn't the entire script, but this is the only part that doesn't work. I have tried var_dump($_FILES);
at the beginning of the script and that returns array(0) { }
Can anyone see from what I have posted why this file upload isn't working?
PS: The form is being submitted via jQuery AJAX. I don't know if it's necessary or not, but here is that AJAX submit:
$.ajax({
type: "POST",
url: url,
data: contactForm.serialize(), // serializes the form's elements.
success: function(data) {
returnMsg.fadeIn();
returnMsg.html(data); // show response from the php script.
if(data.indexOf("success") + 1) {
$('form#contact-form input[type="text"],input[type="email"],textarea').val('');
$('form#contact-form select[name="subject"]').val('Select a subject');
}
}
});
Thanks for taking a look!