I have a webpage that contains a form with several text fields and an optional file upload.
When the user clicks the submit button I do the following:
- check if a file has been selected for upload
- if so, upload the file
- when the file has finished uploading, submit the other form data
My question is this. At the moment, my php server script checks the file as to whether or not it is valid. As of now, I have no way of knowing whether or not the file is valid before submitting the form data. I would like to be able to know that the file was uploaded, valid and also the path where the file was saved.
var xmlhttp=new XMLHttpRequest();
var formData = new FormData();
formData.append("thefile", file);
xmlhttp.addEventListener("load", uploadComplete, false);
xmlhttp.open("POST","uploadfile.php",true);
xmlhttp.setRequestHeader("enctype", "multipart/form-data");
xmlhttp.send(formData);
.
function uploadComplete(evt) {
alert("image upload complete");
submitForm();
}
I basically want to send information from php that can be read from my function uploadComplete