At the time of uploading image i am getting 405 (Method Not Allowd) error. Below are the reference of HTML, JavaSceipt and php file code. I am asking user to upload photo or to capture image using camera and sending it to server . As of now i have take php file
==================
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<title>Clearestream Facial Recognition POC</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<div>Capture Image</div>
<input type="file" capture="camera" accept="image/*" id="cameraInput" name="cameraInput">
<button type="submit" onclick="uploadImage()">Upload</button>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
======================
main.js
====================
var imageFile = document.getElementById("cameraInput").files[0];
function uploadImage() {
var formData = new FormData();
formData.enctype="multipart/form-data";
formData.append("fileToUpload", imageFile);
$.ajax({
url: "http://172.25.63.23:8080/upload.php",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function(response) {
alert("image uploaded");
// .. do something
},
error: function(jqXHR, textStatus, errorMessage) {
console.log(errorMessage); // Optional
alert("error in uploading image");
}
});
}
=================
upload.php
=================
<?php
header("Access-Control-Allow-Origin: *");
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>