Good day everyone,
Before i continue, as i am posting this from the work office, where i have my only internet access i will only be able to start replying by monday. I apologise upfront!
😃
PROBLEM: [EDITED]
Want to upload a given file/document to server using PHP's ftp functions and then attach to generated email that is to be sent via phpMailer. Currently using $FILES array to gain access to the file info so i can use ftp example: $FILES['filename']['name'] ... etc.
Want to add ajax capability, thus use JS functions. So instead of moving to the php file/script directly from the html form i first wish to call some JS functions to validte the info on the form and then use ajax to send the email in the "background" while the user cn continue and then recieve dynamic message stating the message was sent or not sent.
Current attempts in using the "ajax version" leaves my $FILES empty. I would like to ask if anyone knows how i can get the info of the file input field to the php script (via JS functions) so that i may access it through $FILES array, or perhaps so i may access it in different way but get the same values?
DESCRIPTION:
I have a html page with the usual form asking for name lastname email etc etc and it also has input field of type file.
Originally: [EDITED]
.. when setting form's action to procede directly to .php file, i can use the $_FILES 'array' as intended to be able to upload the file to the server and then set the uploaded file as an attachement to an email i wish to send using phpMailer script.
Code of the "Submit" button in the form.
<input type="submit" name="Submit" value="Submit" onClick="sendMyMail(document.getElementById('employment_form'), f_name.value, l_name.value, c_number.value, email.value, ' ', ' ', filenames.value, 'employment')">
The called function validates the form and if valid then procedes to pass all the needed data to the ajax code "sendEmail()". the getTag() function is used to get the parent node of each field as it is validated so that a message of error can be displayed directly after the field dynamically without refreshing anything in the page.
(BELOW CODE IS JAVASCRIPT - DONT KNOW WHAT TAGS TO USE BUT HTML)
function sendMyMail(form, fname, lname, cnum, mail, subj, msg, file, etype)
{
if(validFields(getTag(form),form))
{
document.getElementById('result').innerHTML = "Processing Your Message...";
sendEmail(fname, lname, cnum, mail, subj, msg, file, etype);
clearForm(form);
}
return false;
}
The sendEmail() function: Here is the code of the Ajax entry function
(BELOW CODE IS JAVASCRIPT - DONT KNOW WHAT TAGS TO USE BUT HTML)
function sendEmail(fname,lname,cnum,email, subj, msg, file, etype)
{
.........
if(etype == "employment")
{
http.open('POST','test_emailsend_employment.php?nullv=0&fname='+fname+'&lname='+lname+'&email='+email+'&cnumber='+cnum+'&filenames='+file);
http.onreadystatechange = handleEmail;
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.send('test_emailsend_employment.php?nullv=0&fname='+fname+'&lname='+lname+'&email='+email+'&cnumber='+cnum+'&filenames='+file);
}
}
[EDITED]
Usually it was not needed for me to specify any local variables in the php script to reference the file "value", thus had no $file= $POST[...].
All i had to do was call $FILES['filenames']['...'] directly and use it.
So i reiterate the question, does anyone know how i can get the file values to the php script so that i may use the $_FILES array, so it isnt empty? or so i may use/access the info via other ways to achieve the same result?