Commit 876d653f authored by Okthane's avatar Okthane

Intégration de la fonction vérification

parent c2443606
......@@ -7,15 +7,22 @@
<title>Formulaire d'upload de fichiers</title>
<script src="jquery.js"></script>
<script src="script.js"></script>
<!-- API TenserFlow -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/blazeface"></script>
</head>
<body>
<form id ="form" action="" method="POST" enctype="multipart/form-data">
<form id ="form" action="" method="" enctype="multipart/form-data">
<h2>Upload Fichier</h2>
<div id ="div-ID" >
<canvas id="canvas"></canvas>
<img id="img-ID" src="" />
</div>
<label for="fileUpload">Fichier:</label>
<input type="file" name="photo" id="fileUpload">
<input id="#btnSubmit" type="submit" name="submit" value="Upload">
<p><strong>Note:</strong> Seuls les formats .jpg et .png sont autorisés jusqu'à une taille maximale de 5 Mo.</p>
<!-- <p id="p-status"><strong>Statut :</strong></p> -->
</form>
<div id="div"></div>
</body>
......
// VARIABLES
const URL_CHECK_ID = 'upload.php';
const ID = $("#img-ID");
const canva = $("#canva");
// SCRIPT
$(document).ready(function(){
$("#form").on("submit",function (event) {
event.preventDefault();
var formData = new FormData(this);
$.ajax({
url: 'upload.php',
enctype: 'multipart/form-data',
//url de la requête
url: URL_CHECK_ID,
method: 'POST',
enctype: 'multipart/form-data',
data: formData,
cache: false,
dataType: "json",
contentType: false,
processData: false
})
.done(function(response){
//Traitement de la réponse
let data = JSON.stringify(response);
$("div#div").empty();
$("div#div").append(data);
//Affichage de la photo
})
// findFaces();
});
});
// FONCTIONS
async function findFaces() {
const model = await blazeface.load();
const img = ID;
const predictions = await model.estimateFaces(img, false);
if (predictions.length > 0) {
console.log("faces found")
console.log(predictions);
document.getElementById("status").innerText = "Face(s) found!";
const canvas = canva;
canvas.width = img.width;
canvas.height = img.height;
// const ctx = canvas.getContext("2d");
// ctx.fillStyle = "rgba(250,225,6,0.5)";
// for (let i = 0; i < predictions.length; i++)
// {
// const start = predictions[i].topLeft;
// const end = predictions[i].bottomRight;
// const size = [end[0] - start[0], end[1] - start[1]];
// ctx.fillRect(start[0], start[1], size[0], size[1]);
// var landmark;
// for (let j = 0; j < predictions[i].landmarks.length; j++)
// {
// landmark = predictions[i].landmarks[j];
// ctx.beginPath();
// ctx.arc(landmark[0],landmark[1], 1, 0, 2*Math.PI,false);
// ctx.fill();
// ctx.lineWidth = 1;
// ctx.strokeStyle = '#ff0000';
// ctx.stroke();
// }
// }
}
else {
document.getElementById("status").innerText = "No Face(s) Found";
}
}
<?php
define("PATH_TO_ID", "");
// Vérifier si le formulaire a été soumis
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Vérifie si le fichier a été uploadé sans erreur.
//format de la réponse
if(isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0)
{
$allowed = array("jpg" => "image/jpeg", "png" => "image/png");
......@@ -22,7 +26,7 @@ if($_SERVER["REQUEST_METHOD"] == "POST"){
if(in_array($filetype, $allowed))
{
// Vérifie si le fichier existe avant de le télécharger.
if(file_exists( $_FILES["photo"]["name"]))
if(file_exists(PATH_TO_ID.$_FILES["photo"]["name"]))
{
//echo $_FILES["photo"]["name"] . " existe déjà.";
$message = $_FILES["photo"]["name"] . " existe déjà.";
......@@ -54,6 +58,7 @@ if($_SERVER["REQUEST_METHOD"] == "POST"){
// echo "Error: " . $_FILES["photo"]["error"];
$message = "Error: " . $_FILES["photo"]["error"];
}
header('Content-Type: application/json');
echo json_encode($message);
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment