I want to get the value of <input type="file" id="imageId"/>
using javascript and send it to PHP. I always use jQuery to send data to PHP, but I don't know how to use that on an image without using the form
tag. Here is my code:
<html>
<body>
<input type="file" id="imageId"/>
<br>
<input type="button" value="upload" onclick="getImage()">
</body>
</html>
function getImage(){
var image = document.getElementById("imageId").value;
$.post('backend-process.php', { imageFromJs: image }, function(data) {
if (data == 0) {
alert("successfully Uploaded");
} else{
alert(data);
}
});
}
<?php
$imagetmp = $_FILE['imageFromJs']['tmp_name'];
move_upload_files($imagetmp,"uploads/image.png");
?>
Is there any possible way to make it work without using a usual <form action="upload.php" method="post" enctype="multipart/form-data">
?
Thanks for the help.