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
1d0c5a51
Commit
1d0c5a51
authored
Mar 09, 2022
by
MARQUE Pierre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
requête Ajax
parent
1b1ead26
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
10942 additions
and
16 deletions
+10942
-16
761871ef6ff89cf49dfeab2501d068d2_large.jpg
761871ef6ff89cf49dfeab2501d068d2_large.jpg
+0
-0
817T3-nJexL.jpg
817T3-nJexL.jpg
+0
-0
index.php
index.php
+11
-4
jquery.js
jquery.js
+10881
-0
script.js
script.js
+25
-0
upload.php
upload.php
+25
-12
No files found.
761871ef6ff89cf49dfeab2501d068d2_large.jpg
deleted
100644 → 0
View file @
1b1ead26
489 KB
817T3-nJexL.jpg
0 → 100644
View file @
1d0c5a51
360 KB
index.php
View file @
1d0c5a51
<html
lang=
"fr"
>
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Formulaire d'upload de fichiers
</title>
<script
src=
"jquery.js"
></script>
<script
src=
"script.js"
></script>
</head>
<body>
<form
action=
"upload.php"
method=
"post"
enctype=
"multipart/form-data"
>
<form
id =
"form"
action=
""
method=
"POST"
enctype=
"multipart/form-data"
>
<h2>
Upload Fichier
</h2>
<label
for=
"fileUpload"
>
Fichier:
</label>
<input
type=
"file"
name=
"photo"
id=
"fileUpload"
>
<input
type=
"submit"
name=
"submit"
value=
"Upload"
>
<input
id=
"#btnSubmit"
type=
"submit"
name=
"submit"
value=
"Upload"
>
<p><strong>
Note:
</strong>
Seuls les formats .jpg, .jpeg, .jpeg, .gif, .png sont autorisés jusqu'à une taille maximale de 5 Mo.
</p>
</form>
<div
id=
"div"
></div>
</body>
</html>
\ No newline at end of file
</html>
jquery.js
0 → 100644
View file @
1d0c5a51
This diff is collapsed.
Click to expand it.
script.js
0 → 100644
View file @
1d0c5a51
$
(
document
).
ready
(
function
(){
$
(
"#form"
).
on
(
"submit"
,
function
(
event
)
{
event
.
preventDefault
();
var
formData
=
new
FormData
(
this
);
$
.
ajax
({
url
:
'upload.php'
,
enctype
:
'multipart/form-data'
,
method
:
'POST'
,
data
:
formData
,
cache
:
false
,
dataType
:
"json"
,
contentType
:
false
,
processData
:
false
})
.
done
(
function
(
response
){
let
data
=
JSON
.
stringify
(
response
);
$
(
"div#div"
).
empty
();
$
(
"div#div"
).
append
(
data
);
})
});
});
upload.php
View file @
1d0c5a51
...
...
@@ -2,11 +2,13 @@
// Vérifier si le formulaire a été soumis
if
(
$_SERVER
[
"REQUEST_METHOD"
]
==
"POST"
){
// Vérifie si le fichier a été uploadé sans erreur.
if
(
isset
(
$_FILES
[
"photo"
])
&&
$_FILES
[
"photo"
][
"error"
]
==
0
){
if
(
isset
(
$_FILES
[
"photo"
])
&&
$_FILES
[
"photo"
][
"error"
]
==
0
)
{
$allowed
=
array
(
"jpg"
=>
"image/jpg"
,
"jpeg"
=>
"image/jpeg"
,
"gif"
=>
"image/gif"
,
"png"
=>
"image/png"
);
$filename
=
$_FILES
[
"photo"
][
"name"
];
$filetype
=
$_FILES
[
"photo"
][
"type"
];
$filesize
=
$_FILES
[
"photo"
][
"size"
];
$message
=
""
;
// Vérifie l'extension du fichier
$ext
=
pathinfo
(
$filename
,
PATHINFO_EXTENSION
);
...
...
@@ -17,21 +19,32 @@ if($_SERVER["REQUEST_METHOD"] == "POST"){
if
(
$filesize
>
$maxsize
)
die
(
"Error: La taille du fichier est supérieure à la limite autorisée."
);
// Vérifie le type MIME du fichier
if
(
in_array
(
$filetype
,
$allowed
)){
if
(
in_array
(
$filetype
,
$allowed
))
{
// Vérifie si le fichier existe avant de le télécharger.
if
(
file_exists
(
"upload/"
.
$_FILES
[
"photo"
][
"name"
])){
echo
$_FILES
[
"photo"
][
"name"
]
.
" existe déjà."
;
}
else
{
if
(
file_exists
(
"upload/"
.
$_FILES
[
"photo"
][
"name"
]))
{
//echo $_FILES["photo"]["name"] . " existe déjà.";
$message
=
$_FILES
[
"photo"
][
"name"
]
.
" existe déjà."
;
}
else
{
move_uploaded_file
(
$_FILES
[
"photo"
][
"tmp_name"
],
$_FILES
[
"photo"
][
"name"
]);
echo
"Votre fichier a été téléchargé avec succès."
;
echo
(
"<br></br>"
);
echo
"taille de la photo : "
.
$_FILES
[
"photo"
][
"size"
]
.
" octets"
;
// echo "Votre fichier a été téléchargé avec succès.";
// echo("<br></br>");
// echo "taille de la photo : ".$_FILES["photo"]["size"]." octets";
$message
=
"Votre fichier a été téléchargé avec succès.<br></br> Taille de la photo : "
.
$_FILES
[
"photo"
][
"size"
]
.
" octets"
;
}
}
else
{
echo
"Error: Il y a eu un problème de téléchargement de votre fichier. Veuillez réessayer."
;
}
else
{
// echo "Error: Il y a eu un problème de téléchargement de votre fichier. Veuillez réessayer.";
$message
=
"Error: Il y a eu un problème de téléchargement de votre fichier. Veuillez réessayer."
;
}
}
else
{
echo
"Error: "
.
$_FILES
[
"photo"
][
"error"
];
}
else
{
// echo "Error: " . $_FILES["photo"]["error"];
$message
=
"Error: "
.
$_FILES
[
"photo"
][
"error"
];
}
echo
json_encode
(
$message
);
}
?>
\ No newline at end of file
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