-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_update_profil.php
55 lines (37 loc) · 2.29 KB
/
script_update_profil.php
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
<? function upload($index,$destination,$maxsize=FALSE,$extensions=FALSE)
{
//Test1: fichier correctement uploadé
if (!isset($_FILES[$index]) OR $_FILES[$index]['error'] > 0) return FALSE;
//Test2: taille limite
if ($maxsize !== FALSE AND $_FILES[$index]['size'] > $maxsize) return FALSE;
//Test3: extension
$ext = substr(strrchr($_FILES[$index]['name'],'.'),1);
$extention_photo = strtolower( substr( strrchr($_FILES['photo_profil']['name'], '.') ,1) );
if ($extensions !== FALSE AND !in_array($ext,$extensions)) return FALSE;
//Déplacement
return move_uploaded_file($_FILES[$index]['tmp_name'],$destination);
}
//Créer un identifiant difficile à deviner
$nom = md5(uniqid(rand(), true));
//EXEMPLES
$extention_photo = strtolower( substr( strrchr($_FILES['photo_profil']['name'], '.') ,1) );
$upload1 = upload('photo_profil','uploads/photo_profil/'.$nom.'.'.$extention_photo,19048576, array('png','jpg','jpeg') );
$nom_photo = $nom .".". $extention_photo;
if ($extention_photo == "" AND !isset($_SESSION['profil_photo'])) {
$nom_photo ="";
}
//on met a jour les information
$req = $bdd->prepare('UPDATE usere SET nom_usere =:nom , mail =:email , prenom_usere =:prenom , usere_description =:description , profil_photo =:photo WHERE id_usere =:usere ');
$req->execute(array(
'email' => $_POST['email'],
'prenom' => $_POST['prenom'],
'nom' => $_POST['nomutilisateur'],
'description' => $_POST['description'],
'usere' => $_SESSION['id_usere'],
'photo' => $nom_photo
));
$_SESSION['nom']=$_POST['nomutilisateur'];
$_SESSION['profil_photo'] =$nom_photo;
$req->closeCursor();
header('location:user.php?name=ok');
?>