Commit ccc05d15 authored by Okthane's avatar Okthane

p

parent d8e392df
......@@ -4,6 +4,7 @@
define('WHERE_TO_PUT','img_bg');
define('PATH_TO_BG', "img_bg");
define('TEMP','temp');
require_once "vendor/autoload.php";
......@@ -26,7 +27,7 @@ if($_SERVER["REQUEST_METHOD"] == "POST")
'multipart' => [
[
'name' => 'image_file',
'contents' => fopen('img/'.$filename, 'r')
'contents' => fopen(TEMP.'/'.$filename, 'r')
],
[
'name' => 'size',
......@@ -37,7 +38,10 @@ if($_SERVER["REQUEST_METHOD"] == "POST")
'X-Api-Key' => 'LeteoyV7qPyWtAJF9Rcxenda'
]
]);
// On supprime l'image intermédiaire
$deletefile=unlink(TEMP.'/'.$filename);
//On crée et stocke l'image détourée
$fp = fopen('img_bg/'.pathinfo($filename, PATHINFO_FILENAME)."NO-BG.png", "wb");
fwrite($fp, $res->getBody());
fclose($fp);
......
// VARIABLES ===============================================================================
const URL_CHECK_ID = 'upload.php';
......@@ -9,7 +10,7 @@ const URL_END = 'byebye.html';
const timeout = 5000;
const ID = "img-ID"; var Img;
const ID_bg = "img-ID2"; var ImgBG
const ID_bg = "img-ID2"; var ImgBG;
const canva = "canvas";
// console.log($("#"+ID).attr('src'));
......
<?php
define('PATH_TO_ID', "img");
//dossier temporaitre pour les images
define('PATH_TO_TEMP', "temp");
// Vérifier si le formulaire a été soumis
if($_SERVER["REQUEST_METHOD"] == "POST")
......@@ -31,16 +32,16 @@ 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(PATH_TO_ID."/".$_FILES["photo"]["name"]))
if(file_exists(PATH_TO_TEMP."/".$_FILES["photo"]["name"]))
{
//echo $_FILES["photo"]["name"] . " existe déjà.";
$error = false;
move_uploaded_file($_FILES["photo"]["tmp_name"], PATH_TO_ID."/".$filename);
move_uploaded_file($_FILES["photo"]["tmp_name"], PATH_TO_TEMP."/".$filename);
$message = $_FILES["photo"]["name"] . " existe déjà.";
}
else
{
move_uploaded_file($_FILES["photo"]["tmp_name"], PATH_TO_ID."/".$filename);
move_uploaded_file($_FILES["photo"]["tmp_name"], PATH_TO_TEMP."/".$filename);
// echo "Votre fichier a été téléchargé avec succès.";
// echo("<br></br>");
// echo "taille de la photo : ".$_FILES["photo"]["size"]." octets";
......@@ -67,8 +68,8 @@ if($_SERVER["REQUEST_METHOD"] == "POST")
$message = "Error: " . $_FILES["photo"]["error"];
}
$data = array(
"message" => $message,
"error" => $error,
"message" => $message,//<--Message qui pourra être affiché
"error" => $error,//<----- Prend la valeur true (erreur!) ou false (ouf!)
// "src" => PATH_TO_ID."/".$_FILES["photo"]["name"]
);
echo json_encode($data);
......
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