Bug dans mon script d'Upload de fichiers

Résolu
begueradj Messages postés 273 Date d'inscription dimanche 4 octobre 2009 Statut Membre Dernière intervention 24 juin 2014 - 13 mars 2011 à 16:34
begueradj Messages postés 273 Date d'inscription dimanche 4 octobre 2009 Statut Membre Dernière intervention 24 juin 2014 - 14 mars 2011 à 14:50
Azul,

Il y a quleque chose qui cloche dans mon cul: lorsque je "upload" un fichier pdf dans mon forumlaire je reçois le message indiquant que ce n'est pas un fichier à extension validée or pour moi j'ai bien autorisé ces fichiers PDF,

Ci-dessous mon script, veuillez m'indiquer l'erreur si vous pouvez, merci:

<?php
if(isset($_POST['addport'])){
/*if the submit button that is related to adding a port is validated 
 * then */
 
 /* is the file correctly uploaded ?*/
if(isset($_FILES['photo'])&&($_FILES['photo']['error'])==0){
 
 /* check if the file is not too voluminous */
 if($_FILES['photo']['size']<=3000000000){
 	
 /* extract basic file information */
     $file_info=pathinfo($_FILES['photo']['name']);
 
     /* check the extension of the file */
     $file_extension=$file_info['extension'];
 
    /*the allowed extensions*/
    $allowed_extensions=array('jpg','png','jpeg','gif');
 
    /* check if the file extension is allowed or not */
    if(in_array($file_extension,$allowed_extensions)){
 	
    	$file_name=time().'.'.$file_extension;
 	    copy($_FILES['photo']['tmp_name'],'uploads/'.$file_name);
 	
 	   /*the file has been correctly uploaded */
 	   echo'The file has been correctly uploaded';
 
       if(!empty($_POST['name']) && !empty($_POST['unlocator']) && !empty($_POST['idnumber']) && !empty($_POST['position']) && !empty($_POST['berths']) && !empty($_POST['draft'])){
   /* if all the fields are not empty then */

   /*First , I retrieve all the data */

   $name=$_POST['name'];
   $unlocator=$_POST['unlocator'];
   $idnumber=$_POST['idnumber'];
   $position=$_POST['position'];
   $berths=$_POST['berths'];
   $draft=$_POST['draft'];
   include('../Cfg/config.inc.php');
   $link=mysql_connect($SERVER,$USER,$PWD) or die('Can not connect to the MySQL Server
'.mysql_error());
   mysql_select_db($DB) or die('Can not connect to the requested database
'.mysql_error());
   /* i need to inject the data to the ports table */

           mysql_query("INSERT INTO ports (name,unlocator,idnumber,position,berths,draft,photo)VALUES ('$name','$unlocator','$idnumber','$position','$berths','$draft','$file_name')")or die('Insertion problem
'.mysql_error());
           
           echo'
Ports data is correctly inserted ! 
';
           
   
 }else{
/* at least one of the fields is empty */
 echo'At least one field is empty, please, try again 
!';
    }
  }else{
 	echo'Your photo must have a JPG, JPEG, PNG or GF format !';
 } 
 }/*file is not too voluminous */
}/* file correctly uploaded */	
}/* submit button pressed */

5 réponses

007Julien Messages postés 276 Date d'inscription mercredi 22 septembre 2010 Statut Membre Dernière intervention 8 janvier 2014 4
14 mars 2011 à 14:16
Il s'agit simplement de tester le programme après avoir inséré un echo pour voir quelle est l'extension du fichier reçue et testée après l'upload...

// Insertion pour voir
echo $extensiondufichier;
// avant le test
if(in_array($extensiondufichier,$extensions_autorisees)){
   // ... 
}


Si jamais cette insertion provoquait un message d'erreur contenant headers already sent il conviendrait de retarder cet envoi (voir alors ob_start() et ob_end_flush()).
3
begueradj Messages postés 273 Date d'inscription dimanche 4 octobre 2009 Statut Membre Dernière intervention 24 juin 2014 9
14 mars 2011 à 14:50
Merci Julien, même si j'ai réglé le problème autrement en adoptant une autgre démarche car je n'ai pas le temps pour "débugger" ce script

merci quand même, c'est gentil.
3
begueradj Messages postés 273 Date d'inscription dimanche 4 octobre 2009 Statut Membre Dernière intervention 24 juin 2014 9
13 mars 2011 à 16:36
Je corrige, le script en question est celui-là:









Add files (downloads) :





You can add a new file to your downloads area from here :



0
007Julien Messages postés 276 Date d'inscription mercredi 22 septembre 2010 Statut Membre Dernière intervention 8 janvier 2014 4
13 mars 2011 à 18:42
La première chose à faire est d'imprimer l'extension à la réception.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
begueradj Messages postés 273 Date d'inscription dimanche 4 octobre 2009 Statut Membre Dernière intervention 24 juin 2014 9
14 mars 2011 à 12:20
merci, mais je n'ai pas compris :(
0
Rejoignez-nous