Blocage d'upload PHP

Fermé
vilwix Messages postés 12 Date d'inscription mercredi 23 janvier 2013 Statut Membre Dernière intervention 25 mars 2013 - Modifié par vilwix le 1/02/2013 à 06:17
vilwix Messages postés 12 Date d'inscription mercredi 23 janvier 2013 Statut Membre Dernière intervention 25 mars 2013 - 25 mars 2013 à 17:37
Bonjour,

savez-vous si le fait de mettre enctype multipart/form-data bloque l'upload de l'image dans la base de données mysql?

Si je l'enlève, l'image y est bien uploadée, mais pas dans le ftp. Si je le mets, l'image est bien uploadée dans le ftp mais n'apparaît plus dans la base sql. J'ai pourtant tout tenté...

Je ne sais pas si c'est un problème fréquent.

Voici tout de même mon code


  
<form    method="post"    action="enregistre_conducteur.php?modif=1"   onSubmit="return verification()" enctype='multipart/form-data' >  
   
  <table width="750" border="0">  
    <tr>  
      <td width="240" height="24"><p><strong>Je m'identifie:</strong></p>  
      </td>  
      <td width="500"> </td>  
  </tr>  
  </table>  
    
    <table width="750" border="0">  
    <tr>  
      <td width="240" height="24"><div align="right">Mon nom</div></td>  
      <td width="500"><input name="prenom" type="text" <?php echo "value=\"$prenom\""; ?>   onFocus="javascript:this.value=''" >  
        <input name="nom" type="text" <?php echo "value=\"$nom\""; ?> onFocus="javascript:this.value=''" ></td>  
    </tr>  
 </table>  
   
 <table width="750" border="0">  
    <tr>  
      <td width="240" height="24"><div align="right">Mon pseudo*</div></td>  
      <td width="500"><input type="text" name="pseudo" <?php echo "value=\"$pseudo2\""; ?> ></td>  
    </tr>  
 </table>  
   
 <table width="100%" border="0">  
<tr>  
<td>  

 <input type="hidden" name="MAX_FILE_SIZE" value="20000000" />  
<input   name="fichier_upload" id="fichier_upload" type="file" onFocus="javascript:this.value=''"  ><br>  
   


</table>  




 <table width="750" border="0">  
    <tr>  
      <td height="8"></td>  
    </tr>  
 </table>  
    
 <table width="750" border="0">  
  <tr>  
    <td width="240" height="24"><div align="right">Je choisis un mot de passe*</div></td>  
    <td width="500"><input type="password" name="pwd" <?php echo "value=\"$pwd\""; ?> ></td>  
  </tr>  
 </table>  
    
  <table width="750" border="0">  
  <tr>  
    <td width="240" height="24"><div align="right">Je confirme le mot de passe*</div></td>  
      <td width="500"><input type="password" name="pwd2" <?php echo "value=\"$pwd\""; ?>></td>  
  </tr>  
    
    

 </table>  
<p> </p>  
<p><strong>Pour me joindre:</strong></p>  
<table width="750" border="0">  
  <tr>  
    <td width="240" height="24"><div align="right">Mon adresse mail*      </div></td>  
    <td width="500"><input type="text" name="mail" <?php echo "value=\"$mail\""; ?>></td>  
  </tr>  
</table>  

 <table width="750" border="0">  
  <tr>  
    <td width="240" height="24"><div align="right">Mon téléphone</div></td>  
    <td width="500"><input type="text" name="tel" <?php echo "value=\"$tel\""; ?>></td>  
  </tr>  
 </table>  

   
<p>* champs obligatoires</p>  



et le fichier qui upload l'image:


<html>
<head>
<title>Upload</title>
</head>

<body>

<?php
if($_FILES['fichier_upload']['error']==0) {
// process
} else {
// handle the error
}
?>


<?php
if(!empty($_FILES['fichier_upload']['name']))
{
// on récupère les infos du fichier à uploader
$fichier_temp = $_FILES['fichier_upload']['tmp_name'];
$fichier_nom = $_FILES['fichier_upload']['name'];


// on défini les dimensions et le type du fichier
list($fichier_larg, $fichier_haut, $fichier_type, $fichier_attr)=getimagesize($fichier_temp);

// infos de contrôle du fichier
$fichier_poids_max = 500000;
$fichier_h_max = 2448;
$fichier_l_max = 3264;

// dossier de destination
$fichier_dossier = 'avatar/';

// extension du fichier
$fichier_ext = substr($fichier_nom,strrpos( $fichier_nom, '.')+1);

// on renomme le fichier
$fichier_date = date("ymdhis");
$fichier_n_nom = $fichier_date.".".$fichier_ext;

// on vérifie s'il y a bien un fichier à uploader
if (!empty($fichier_temp) && is_uploaded_file($fichier_temp))
{
// on vérifie le poids du fichier
if (filesize($fichier_temp)<$fichier_poids_max)
{
// types de fichiers autorises 1=gif / 2=jpg / 3=png
if (($fichier_type===1) || ($fichier_type===2) || ($fichier_type===3))
{
// on vérifie si l'image n'est pas trop grande
if (($fichier_larg<=$fichier_l_max) && ($fichier_haut<=$fichier_h_max))
{

// si le fichier est ok, on l'upload sur le serveur
if (move_uploaded_file($fichier_temp, $fichier_dossier.$fichier_n_nom))
{
echo "Le fichier a été uploadé avec succès<br />";
echo '<a href="'.$fichier_dossier.$fichier_n_nom.'"><img src="'.$fichier_dossier.$fichier_n_nom.'"></a><br />';
}
else
echo "Le fichier n'a pas pu être uploadé<br />";
}
else
echo "Le fichier est trop grand<br />";
}
else
echo "Le fichier n'a pas le bon format<br />";
}
else
echo "Le fichier est trop lourd<br />";
}
else
echo "Pas de fichier à uploader<br />";
}
?>

</td>
</tr>
</table>
</body>
</html>



Enfin, pour afficher l'image d'un utilisateur, je mets ce sript: echo '<img src="avatar/'.$fichier_nom['fichier_upload'].'">"'; je ne sais pas si c'est le bon. J'en ai tenté d'autres.

Merci d'avance!!



A voir également:

2 réponses

gardiendelanuit Messages postés 1769 Date d'inscription jeudi 20 décembre 2007 Statut Membre Dernière intervention 19 novembre 2016 264
13 mars 2013 à 10:52
Bonjour,

Où est-ce que tu utilises une base de données dans ton script ?
0
vilwix Messages postés 12 Date d'inscription mercredi 23 janvier 2013 Statut Membre Dernière intervention 25 mars 2013
25 mars 2013 à 17:37
Oui, bien sûr. Une base de donnée sql
0