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

Langage PHP Discussion :

[Upload] Problème pour uploader un fichier dans mon code


Sujet :

Langage PHP

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mai 2006
    Messages : 9
    Points : 10
    Points
    10
    Par défaut [Upload] Problème pour uploader un fichier dans mon code
    Salut a vous,
    je ne suis pas capable de mettre mon script uploader dans ce script en fat je ne sais pas ou.
    Php 4
    windows 2003

    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
    138
     
    <?php
    if (!isset($_POST['submit']))
     
    {
     
     
     
    ?>
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <head>
     
    </head>
     
    <body bgcolor="#000000" text="white" vlink="orange" link="white" alink="yellow" >
     
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
    Nom : <input type="text" name="nom"><br>
    Date d'affichage : <input type="text" name="affiche"><br>
    Courriel : <input type="text" name="courriel"><br>
     
    &Eacute;v&egrave;nement : <input type="text" name="evenement"><br>
    Date de l' &eacute;v&egrave;nement : <input type="text" name="date"><br>
    <input type="hidden" name="MAX_FILE_SIZE" value="200000" />
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
     
     
    <input type="submit" name="submit" value="Submit">
    </form>
    </body>
    </html>
     
     
     
     
    <?php
     
     
     
     
    }else{
     
     
     
     
    ?>
     
    <!doctype html public "-//w3c//dtd html 3.2//en">
     <html>
    <head>
     
     
     
     
    </head>
     
    <body bgcolor="#000000" text="white" vlink="black" link="black" alink="black" >
     
     
     
     
     
    <br><br>
    <b>Voici votre r&eacute;sultat <?php echo $_POST['nom']; ?> :</b><hr>
     
     
     
     
    <table border="0" align="center" cellspacing="1" cellpading="0" >
    <tr><td bgcolor="#000000" class="white" align="center"><table border=0 align="center" cellspacing="1" cellpading="0" >
    <tr><td bgcolor="#cccc99" class="white" align="left" width="500">
    Nom : <?php echo $_POST['nom']; ?><br>
    Date d'affichage :  <?php echo $_POST['affiche']; ?><br>
    Courriel : <?php echo $_POST['courriel']; ?><br><br>
     
    &Eacute;v&egrave;nement : <?php echo $_POST['evenement']; ?><br>
    Date de l' evenement : <?php echo $_POST['date']; ?>
     
    </td>
     
        <td bgcolor="#cccc99" class="white" align="left" width="100"><img src="<?php echo "http://www.test.peuplies.info/AAA Model Editor/upload/".$_POST['uploadedfile']; ?>" width="100" border="0">
     
    </td>
    </tr>
    </table>
    </table>
     
     
     
    <br><br>
    <hr>
     
     
    <form action="addtest11write.php?codes=codesource" method="POST">
     
    <center>
    <textarea cols="80" rows="20" wrap="off" name="codesource" >
    <table border="0" align="center" cellspacing="1" cellpading="0" >
    <tr><td bgcolor="#000000" class="white" align="center"><table border="0" align="center" cellspacing="1" cellpading="0" >
    <tr><td bgcolor="#cccc99" class="white" align="left" width="500">
    Nom : <?php echo $_POST['nom']; ?><br>
    Date d'affichage : <?php echo $_POST['affiche']; ?><br>
    Courriel : <?php echo $_POST['courriel']; ?><br><br>
     
    &Eacute;venement : <?php echo $_POST['evenement']; ?><br>
    Date de l' evenement : <?php echo $_POST['date']; ?><br>
     
    </td>
     
        <td bgcolor="#cccc99" class="white" align="left" width="100"><img src="<?php echo "http://www.test.peuplies.info/AAA Model Editor/upload/".$_POST['uploadedfile']; ?>" width="100" border="0">
     
    </td>
    </tr>
    </table>
    </table>
     
    </textarea>
    </center>
     
     
    <input type="submit" name="confirm" value="Confirm">
    </form>
     
    </body>
    </html> 
     
     
    <?php
    }
     
     
     
     
     
     
     
    ?>

    Voici mon code pour mon uploader

    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
     
     
     
     
    // Where the file is going to be placed
    $target_path = "uploads/";
     
    /* Add the original filename to our target path. Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
     
    // This is how we will get the temporary file...
    $_FILES['uploadedfile']['tmp_name'];
     
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }

  2. #2
    Membre averti

    Homme Profil pro
    Ingénieur qualité méthodes
    Inscrit en
    Mars 2004
    Messages
    220
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur qualité méthodes
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mars 2004
    Messages : 220
    Points : 322
    Points
    322
    Par défaut
    et ne nous donne pas tout ton code, juste ce qui ne va pas (ici le code php aurait fait l'affaire).
    "Une méthode fixe n'est pas une méthode" (Proverbe chinois)

  3. #3
    Membre régulier
    Profil pro
    Développeur Web
    Inscrit en
    Décembre 2004
    Messages
    97
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2004
    Messages : 97
    Points : 89
    Points
    89
    Par défaut
    tu peux déjà changer :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
    1ere solution :
    Au dessus de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <input type="submit" name="confirm" value="Confirm">
    tu ajoutes ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <input type="hidden" name="upload" value="1">
    entre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <body bgcolor="#000000" text="white" vlink="orange" link="white" alink="yellow" >
    et
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
    tu ajoutes ceci :
    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
     
    <?php
    $upload= empty($_POST[upload]) ? -1 : $_POST[upload];
     
    if ($upload == 1) {
    // Where the file is going to be placed
    $target_path = "uploads/";
     
    /* Add the original filename to our target path. Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
     
    // This is how we will get the temporary file...
    $_FILES['uploadedfile']['tmp_name'];
     
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    }
    2ème solution :
    supposons que ta page avec le formulaire s'appelle "formupload.html"
    Dans "formupload.html", tu changes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
    deviens
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <form enctype="multipart/form-data" action="uploadhandler.php" method="post" >
    tu crees une page qui s'appelle "uploadhandler.php" dans laquelle tu mets :
    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
     
    // Where the file is going to be placed
    $target_path = "uploads/";
     
    /* Add the original filename to our target path. Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
     
    // This is how we will get the temporary file...
    $_FILES['uploadedfile']['tmp_name'];
     
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    //une redirection vers formupload.html
    voilà,

    Philippe

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

Discussions similaires

  1. [Débutant] problème pour gerer plusieurs onglets dans mon navigateur
    Par sergeooo dans le forum VB.NET
    Réponses: 0
    Dernier message: 26/03/2012, 20h12
  2. Réponses: 0
    Dernier message: 07/06/2010, 15h47
  3. Problème pour lister des fichiers dans une interface
    Par sapristy dans le forum GTK+ avec C & C++
    Réponses: 2
    Dernier message: 23/02/2010, 14h00
  4. Réponses: 9
    Dernier message: 20/02/2009, 17h51
  5. Réponses: 4
    Dernier message: 27/05/2007, 11h11

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