-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit-profil.php
More file actions
76 lines (61 loc) · 2.36 KB
/
edit-profil.php
File metadata and controls
76 lines (61 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
require 'vendor/autoload.php';
use Gregwar\Image\Image;
require('inc/functions.php');
checkConnection();
if(!isConnected()) {
header('Location: index.php');
exit;
}
require('inc/database.php');
$errors = array();
$success = false;
if(!empty($_FILES['avatar']) && !empty($_FILES['avatar']['type'])){
/* $type = $_FILES['avatar']['type'];
$size = $_FILES['avatar']['size'];
$pixelSize = getimagesize($_FILES['avatar']['tmp_name']);
if(!(strstr($type, 'jpg') || strstr($type, 'jpeg'))){
$errors['avatar'] = 'Cette image n\'est pas une image jpg';
}
if($size > 1000000){
$errors['avatar'] = 'Cette image est trop grande (<1Mo) ';
}
if($pixelSize[0] > 512 || $pixelSize[1] > 512 ){
$errors['avatar'] = 'Cette image est trop grande (128x128 max) ';
} */
$errors = uploadValid($errors, 'avatar', $_FILES['avatar'], 1000000, ['.jpg', '.jpeg'], ['image/jpeg','image/jpg']);
$avatar = $_FILES['avatar']['tmp_name'];
if(count($errors)==0) {
$id = $_SESSION['user']['identifier'];
if($avatar !== null){
move_uploaded_file($avatar,'assets/uploads/avatars/'.$id.'.jpg');
$avatar = 'assets/uploads/avatars/'.$id.'.jpg';
$image = Image::open($avatar);
$image->resize(256, 256)
->save('assets/uploads/avatars/'.$id.'-256x256.jpg');
$image->resize(128, 128)
->save('assets/uploads/avatars/'.$id.'-128x128.jpg');
$image->resize(64, 64)
->save('assets/uploads/avatars/'.$id.'-64x64.jpg');
$sql = 'update users set avatar = :avatar where id = :id';
$query = $pdo ->prepare($sql);
$query -> bindValue(':avatar', $avatar);
$query -> bindValue(':id', $id, PDO::PARAM_INT);
$query->execute();
$success = true;
}
}
}
include('inc/header.php'); ?>
<?php if($success){ ?>
<p>Avatar modifié!</p>
<?php }else{ ?>
<form action="" method="POST" enctype="multipart/form-data">
<label for="avatar">Votre avatar</label>
<input class="noms" type="file" id="avatar" name="avatar" >
<span class="error"><?php if(!empty($errors['avatar'])){echo $errors['avatar'];}?></span>
<input class="button" type="submit" name="submitted" value="Valider">
</form>
<?php } ?>
<?php
include('inc/footer.php');