Bonjour,
j'ai 2 petits problèmes avec mon script Update membre

1-quand un utilisateur vient faire une modification a son profil et qu'il ne met rien dans la case photo, le traitement update vient écraser et effacer l'ancienne inscription photo dans la table.


2- Dans mon script function insertPhoto()
j'ai une restriction limite a 200K mais voila que si un membre ajoute une photo depassant 200k, le traitement update se fait quand meme et inscrit le nom de la photo dans la table mais elle n'est pas Uploader dans ../images.

j'aimerais bien savoir comment je pourrais améliorer mon code pour la bonne gestion des upolad photos dans mon Update membre.

merci

je vous mets ici le script photo du formulaire: mod_voiturier.php

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
<p>    
      <label for="photo">Modifier une photo</label>
      <input type="hidden" name="MAX_FILE_SIZE"  value="200000" />
      <input type="file" name="photo" id="photo" value="<?php echo $info['photo'];?>" />
    </p>
et update_voiturier.php

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
 
function insertPhoto() {
  if (isset($_FILES['photo'])) 
    {
 
      $fichier = basename($_FILES['photo']['name']);
      $taille_maxi = 200000;
      $taille = filesize($_FILES['photo']['tmp_name']);
      $extensions = array('image/png', 'image/gif', 'image/jpg', 'image/jpeg', 'image/bmp');
      //$extension = strrchr($_FILES['photo']['name'], '.');
      $extension = $_FILES['photo']['type'];
      //Début des vérifications de sécurité...
 
      if($_FILES['photo'] ['error'] != 0)
	{
	  echo ' une erreur est rencontree !';
	  echo $_FILES['photo']['error'];
	}
      elseif(!in_array($extension, $extensions)) //Si l'extension n'est pas dans le tableau
	{
	  echo 'Vous devez uploader un fichier de type png, gif, jpg, jpeg, ou bmp...';
	}
      elseif($taille>$taille_maxi)
	{
	  echo 'Erreur!! Le fichier depasse 200 K...';
	}
      else // s'il n'y a pas d'erreur on upload!
	{
	  //On formate le nom du fichier ici...
	  $fichier = strtr($fichier, 
			   'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 
			   'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
	  $fichier = preg_replace('/([^.a-z0-9]+)/i', '-', $fichier)or die(mysql_error());
	  $dossier = '../images/'or die(mysql_error());
	  if(move_uploaded_file($_FILES['photo']['tmp_name'], $dossier . $fichier)) //Si la fonction renvoie TRUE, c'est que ça a fonctionné...
	    {
	      echo 'Upload effectué avec succès !';
	    }
	  else //Sinon (la fonction renvoie FALSE).
	    {
	      echo 'Echec de l\'upload !';
	    }
 
	}
    }
}
 
 function checkForm() {
   if ($_POST['email'] != "" &&
       $_POST['pseudo'] != ""
      ) {
     return true;
   }
 
   return false;
 }
 
function updateVoiturier() {
  if (isset($_FILES['photo'])) {
    $photo = mysql_real_escape_string(htmlspecialchars($_FILES['photo']['name']));  
  } else {
    $photo = '';
  }
  $nom = mysql_real_escape_string(htmlspecialchars($_POST['nom']));
  $prenom = mysql_real_escape_string(htmlspecialchars($_POST['prenom']));
  $adresse = mysql_real_escape_string(htmlspecialchars($_POST['adresse']));
  $ville = mysql_real_escape_string(htmlspecialchars($_POST['ville']));
  $pays = mysql_real_escape_string(htmlspecialchars($_POST['pays']));
  $province = mysql_real_escape_string(htmlspecialchars($_POST['province']));
  $code_postal = mysql_real_escape_string(htmlspecialchars($_POST['code_postal'])); 
  $telephone = mysql_real_escape_string(htmlspecialchars($_POST['telephone']));
  $cellulaire = mysql_real_escape_string(htmlspecialchars($_POST['cellulaire']));
  $occupation = mysql_real_escape_string(htmlspecialchars($_POST['occupation']));
  $sexe = mysql_real_escape_string(htmlspecialchars($_POST['sexe']));
  $annee = mysql_real_escape_string(htmlspecialchars($_POST['annee']));
  $mois = mysql_real_escape_string(htmlspecialchars($_POST['mois']));
  $jour = mysql_real_escape_string(htmlspecialchars($_POST['jour']));
  $date_naissance = $annee . "-" . $mois . "-"  . $jour;
  //$pseudo = mysql_real_escape_string(htmlspecialchars($_POST['pseudo']));
  $email = mysql_real_escape_string(htmlspecialchars($_POST['email']));
  $password = mysql_real_escape_string(htmlspecialchars($_POST['password']));
  $date_inscription = date('Y-m-d');
  $permis_conduire = mysql_real_escape_string(htmlspecialchars($_POST['permis_conduire']));
  $annee_experience = mysql_real_escape_string(htmlspecialchars($_POST['annee_experience']));
  $message    = mysql_real_escape_string(htmlspecialchars($_POST['message']));
 
  $sql="  UPDATE gestion_voiturier 
	  SET nom =     '" . $nom . "',
              prenom =  '" . $prenom . "',
              adresse = '" . $adresse . "',
              ville = '" . $ville . "', 
              pays =  '" . $pays . "' ,
              province = ' " . $province . "',
              code_postal = '" . $code_postal . "',
              telephone = '" . $telephone . "',
              cellulaire = '" . $cellulaire .  "',
              occupation = '" . $occupation . "',
              sexe = '" . $sexe . "' ,
              date_naissance = '" . $date_naissance . "' ,
              message = '" . $message . "' ,
              email = '" . $email . "',
              date_inscription = '" . $date_inscription . "',
              photo = '" . $photo . "' ,
              annee_experience = '" . $annee_experience . "',
              permis_conduire =  '" . $permis_conduire . "' 
           
          WHERE membres_id = " . $_SESSION['membreID'];
 
  echo $sql;
  if (!mysql_query($sql))
    {
      die('Erreur - table gestion_voiturier: ' . mysql_error());
    }
  if (!mysql_query($sql))
  {
    die('Erreur - table voitures:' . mysql_error());
  }
  if (isset($password)) {
    $sql = "UPDATE membres set password = md5('" . $password . "') WHERE id = " . $_SESSION['membreID'];
    mysql_query($sql) or die(mysql_error());
  }
  header( "Location: session_voiturier.php" );
}
 
$show_form = true;
if (isset($_POST['submit'])) {
  if (isset($_POST['email'])) { 
    insertPhoto();
    updateVoiturier();
 
	die();
  } else {
   die("check pseudo");
  }
}
?>