IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

EDI, CMS, Outils, Scripts et API PHP Discussion :

Télécharger plusieurs images a partir d'un formulaire ?


Sujet :

EDI, CMS, Outils, Scripts et API PHP

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    72
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2005
    Messages : 72
    Points : 40
    Points
    40
    Par défaut Télécharger plusieurs images a partir d'un formulaire ?
    Hello, Voici mon problème,

    J’ai un petit catalogue sur lequel je voudrais pouvoir télécharger des photos.
    J’ai trouvé sur le net un formulaire Javascript qui permet de télélcharger plusieurs photos en même temps … ensuite j'ai bidouillé un code Php d'envoi.... les photos s’inscrivent bien dans la base de données Mais ne sont pas téléchargées….

    Comment faire cela ?
    Qui pourrait m’aider ?

    Je laisse les 2 codes ci-dessous, merci de bien vouloir jeter un œil. Merci

    Le voici le code du formulaire :
    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
     
    <form action="load.php" 
    method="post" 
    enctype="multipart/form-data" 
    name="envoi_fichiers" 
    target="_self" 
    id="envoi_fichiers">
    dessin 
      <input type="file" name="fichier_1" /><br />
    photo1 
    <input type="file" name="fichier_2" /><br />
    photo2 
    <input type="file" name="fichier_3" /><br />
    photo3 
    <input type="file" name="fichier_4" /><br />
    photo4 
    <input type="file" name="fichier_5" /><br />
    <span id="leschamps_6"><a href="javascript:create_champ(6)"></a></span>
                                  <br />
                                  <br />
                                  <br />
       <input type="submit" name="Submit" id="Submit" value="Ins&eacute;rer" />
    <input type="hidden" name="MAX_FILE_SIZE" value="70000" />
    </form>


    code PHP d’envoi vers la BDD :

    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
     
    <?php
    //Verif champs
    if(!empty($_FILES["fichier_1"]["name"]))
    if(!empty($_FILES["fichier_2"]["name"]))
    if(!empty($_FILES["fichier_3"]["name"]))
    if(!empty($_FILES["fichier_4"]["name"]))
    if(!empty($_FILES["fichier_5"]["name"]))
    {
    	//nom fichiers
    	$nomFichier    = $_FILES["fichier_1"]["name"] ;
    	$nomFichier    = $_FILES["fichier_2"]["name"] ;
    	$nomFichier    = $_FILES["fichier_3"]["name"] ;
    	$nomFichier    = $_FILES["fichier_4"]["name"] ;
    	$nomFichier    = $_FILES["fichier_5"]["name"] ;
     
     
    	$nomTemporaire = $_FILES["fichier_1"]["tmp_name"] ;
    	$nomTemporaire = $_FILES["fichier_2"]["tmp_name"] ;
    	$nomTemporaire = $_FILES["fichier_3"]["tmp_name"] ;
    	$nomTemporaire = $_FILES["fichier_4"]["tmp_name"] ;
    	$nomTemporaire = $_FILES["fichier_5"]["tmp_name"] ;
     
    	$typeFichier   = $_FILES["fichier_1"]["type"] ;
    	$typeFichier   = $_FILES["fichier_2"]["type"] ;
    	$typeFichier   = $_FILES["fichier_3"]["type"] ;
    	$typeFichier   = $_FILES["fichier_4"]["type"] ;
    	$typeFichier   = $_FILES["fichier_5"]["type"] ;
     
    	$poidsFichier  = $_FILES["fichier_1"]["size"] ;
    	$poidsFichier  = $_FILES["fichier_2"]["size"] ;
    	$poidsFichier  = $_FILES["fichier_3"]["size"] ;
    	$poidsFichier  = $_FILES["fichier_4"]["size"] ;
    	$poidsFichier  = $_FILES["fichier_5"]["size"] ;
     
    //code erreur:
    	$codeErreur    = $_FILES["fichier_1"]["error"] ;
    	$codeErreur    = $_FILES["fichier_2"]["error"] ;
    	$codeErreur    = $_FILES["fichier_3"]["error"] ;
    	$codeErreur    = $_FILES["fichier_4"]["error"] ;
    	$codeErreur    = $_FILES["fichier_5"]["error"] ;
     
    	$chemin = "../photos/" ; …?>

  2. #2
    Membre confirmé
    Profil pro
    Développeur Web
    Inscrit en
    Avril 2006
    Messages
    430
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Avril 2006
    Messages : 430
    Points : 557
    Points
    557
    Par défaut
    Salut,

    t'es certain que tes photos sont bien "enregistrées" dans la DB? c'est ton script d'envoi qui fait ca ?
    parce que là, ca me parait impossible...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    if(!empty($_FILES["fichier_1"]["name"]))
    if(!empty($_FILES["fichier_2"]["name"]))
    if(!empty($_FILES["fichier_3"]["name"]))
    if(!empty($_FILES["fichier_4"]["name"]))
    if(!empty($_FILES["fichier_5"]["name"]))
    {
    ca représente quoi ca ?

    Et ca :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
     $nomFichier    = $_FILES["fichier_1"]["name"] ;
     $nomFichier    = $_FILES["fichier_2"]["name"] ;
     $nomFichier    = $_FILES["fichier_3"]["name"] ;
     $nomFichier    = $_FILES["fichier_4"]["name"] ;
     $nomFichier    = $_FILES["fichier_5"]["name"] ;
    ca sert à quoi?

    Y'a un sérieux travail à faire du côté de ce script... Penser aux boucles, écrire une structure correcte de if...
    Merci à Microsoft pour avoir transformé un métier relativement terne et basé sur une approche bêtement technique et rigoureuse des faits, en challenge quotidien, nécessitant une remise en question permanente à l'échelle du quart d'heure

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    72
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2005
    Messages : 72
    Points : 40
    Points
    40
    Par défaut
    OUI, j'ai tout recommencé plus simplement, comme ca tout s'enregistre dans la base mais j'arrive pas a télécharger les photos... qui peut m'aider à résoudre ce problème? Merci

    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
     
    if(!empty($_FILES["fichier_1"]["name"]))
    if(!empty($_FILES["fichier_2"]["name"]))
    {
    	$nomFichier    = $_FILES["fichier_1"]["name"] ;
                 $nomFichier    = $_FILES["fichier_2"]["name"] ;
     
    	$nomTemporaire = $_FILES["fichier_1"]["tmp_name"] ;
    	$nomTemporaire = $_FILES["fichier_2"]["tmp_name"] ;
     
    	$typeFichier   = $_FILES["fichier_1"]["type"] ;
    	$typeFichier   = $_FILES["fichier_2"]["type"] ;
     
    	$poidsFichier  = $_FILES["fichier_1"]["size"] ;
    	$poidsFichier  = $_FILES["fichier_2"]["size"] ;
     
    	$codeErreur    = $_FILES["fichier_1"]["error"] ;
    	$codeErreur    = $_FILES["fichier_2"]["error"] ;
     
    	$chemin = "/photos/" ;

  4. #4
    Membre expérimenté Avatar de julien.63
    Profil pro
    balayeur
    Inscrit en
    Décembre 2005
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : balayeur

    Informations forums :
    Inscription : Décembre 2005
    Messages : 1 348
    Points : 1 311
    Points
    1 311
    Par défaut
    Est ce que tu as un message d'erreur ?
    Est ce que tu as une idée d'où ton script ne fonctionne plus?

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    72
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2005
    Messages : 72
    Points : 40
    Points
    40
    Par défaut
    J'avais un parse error mais j'ai pu le corriger, il manquait ca à la fin

    Sinon, tout s'inscrit dans la base mais seule 1 des 2 photos est téléchargée sur la page... Si qq'un voit comme résoudre mon problème, d'avance merci pour votre aide.

  6. #6
    Membre régulier

    Profil pro
    Inscrit en
    Juin 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 94
    Points : 120
    Points
    120
    Par défaut
    en essayant un code plus simple:
    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
    <?
    $chemin = "../photos/";
    foreach ($_FILES as $tmp_file) {
       // ça ne traite que les $_FILES remplis
       $nomFichier = $tmp_file["name"];
       $nomTemporaire = $tmp_file["tmp_name"];
       $poidsFichier  = $tmp_file["size"];
       if (move_uploaded_file($nomTemporaire, $chemin.$nomFichier)) {
          if (!getimagesize($chemin.$nomFichier)) {
             unlink($chemin.$nomFichier);
             echo "$nomFichier n'est pas une image<br />\n";
          }
       }
    }
    ?>

  7. #7
    Membre expérimenté

    Homme Profil pro
    Inscrit en
    Janvier 2004
    Messages
    1 249
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 1 249
    Points : 1 565
    Points
    1 565
    Par défaut
    Citation Envoyé par loady
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    $nomFichier    = $_FILES["fichier_1"]["name"] ;
            $nomFichier    = $_FILES["fichier_2"]["name"] ;
     
    	$nomTemporaire = $_FILES["fichier_1"]["tmp_name"] ;
    	$nomTemporaire = $_FILES["fichier_2"]["tmp_name"] ;
     
    	$typeFichier   = $_FILES["fichier_1"]["type"] ;
    	$typeFichier   = $_FILES["fichier_2"]["type"] ;
     
    	$poidsFichier  = $_FILES["fichier_1"]["size"] ;
    	$poidsFichier  = $_FILES["fichier_2"]["size"] ;
     
    	$codeErreur    = $_FILES["fichier_1"]["error"] ;
    	$codeErreur    = $_FILES["fichier_2"]["error"];
    Comprend tu ce que tu fait ?
    Quand tu défini une variable, il ne sert absoluement a rien de la définir 2 fois.
    toutes les lignes du genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $a=(truc);
    $a=(machin);
    peuvent toujours etres remplacées par : $a=(machin);
    la ligne $a=(truc); ne servant absoluement a rien...

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    72
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2005
    Messages : 72
    Points : 40
    Points
    40
    Par défaut
    Hello,

    CrazyCat > MERCI pour ton aide.

    FladNag > non, je comprends pas tout, je suis débutant, J'apprends par la pratique.


  9. #9
    Membre régulier

    Profil pro
    Inscrit en
    Juin 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 94
    Points : 120
    Points
    120
    Par défaut
    Alors si tu apprends, voici une grande leçon concernant ton script:
    lorsque tu fais:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    $nomFichier    = $_FILES["fichier_1"]["name"] ;
    $nomFichier    = $_FILES["fichier_2"]["name"] ;
    $nomFichier    = $_FILES["fichier_3"]["name"] ;
    $nomFichier    = $_FILES["fichier_4"]["name"] ;
    $nomFichier    = $_FILES["fichier_5"]["name"] ;
    tu te retrouves au final avec $nomFichier qui contient la dernière valeur.
    C'est pourquoi il vaut mieux fonctionner par boucles et faire tout ton traitement avant de passer à la suite.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Upload] Télécharger plusieurs images en même temps
    Par tarzanjane dans le forum Langage
    Réponses: 3
    Dernier message: 14/04/2009, 12h32
  2. Réponses: 4
    Dernier message: 27/08/2007, 13h24
  3. [Conception] Afficher les images a partir d'un formulaire
    Par rane dans le forum PHP & Base de données
    Réponses: 13
    Dernier message: 23/08/2006, 15h16
  4. télécharger plusieurs images en même temps
    Par batama dans le forum Balisage (X)HTML et validation W3C
    Réponses: 3
    Dernier message: 27/04/2006, 15h24
  5. importer une image a partir d'un formulaire
    Par Malo dans le forum Général Conception Web
    Réponses: 3
    Dernier message: 16/03/2006, 09h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo