Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Projet ISIS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MARQUE Pierre
Projet ISIS
Commits
ccc05d15
Commit
ccc05d15
authored
Mar 28, 2022
by
Okthane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p
parent
d8e392df
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
8 deletions
+14
-8
removeBackground2.php
removeBackground2.php
+5
-1
script.js
script.js
+2
-1
upload.php
upload.php
+7
-6
No files found.
removeBackground2.php
View file @
ccc05d15
...
...
@@ -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
);
...
...
script.js
View file @
ccc05d15
// 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'));
...
...
upload.php
View file @
ccc05d15
<?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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment