I am trying to send with ajax a photo from javascript to php. I have this input in html:
<input type="file" class="input-field" id="photo" name="photo">
this in javascript:
var photo = document.getElementById("photo").value;
and this in php:
$photo_location = $_FILES['photo']['tmp_name'];
I am using ajax post to send the photo and some other data in php. All other data are received correctly in php except the photo. is the getelementbyid .value method which gets the photo wrong ? i get an error undefined index photo from php.
xmlhttp.open("POST", "ajaxpost.php");
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var payload = "name=" + name + "&price=" + price + "&quantity=" + quantity + "&description=" + description + "&photo=" + photo;
payload = payload.replace("%20", "+");
payload = payload.replace("%3D", "=");
xmlhttp.send( payload );
return false;