All pastes #168874 Raw Edit

Sans titre

public text v1 · immutable
·published 2006-09-13 12:27 UTC
rendered paste body
Formulaire :


<table width="80%" border="1" cellspacing="0" class="texte11pix" bordercolor="silver" bordercolordark="white" bordercolorlight="silver" background="images/commun/fond.gif">
  <tr>
    <td class="txt1">
      <form action="ajout_photos_recettes.php" method="post" enctype="multipart/form-data" target="_self">
        <p align="center"><b><br>Ajout photos recette :</b></p>
        <table align="center" class="texte11pix" cellpadding="5" cellspacing="0" width="100%" bordercolordark="white" bordercolorlight="black">
          <tr>
            <td width="40%" class="txt1">Alt :  <br>
              <input name="alt" type="text" maxlength="50" size="50" value="" >
            </td>
          </tr>
          <tr>
            <td width="40%" class="txt1">Photo :  <br>
              <input type="file" name="fichier" id="fichier">
            </td>
          </tr>
          <tr>
            <td width="40%" class="txt1"><input type="submit" name="Envoyer"><input type="hidden" name="id_recettes" value="<? echo $_GET["id"]; ?>">
            <td width="40%" class="txt1"><input type="reset"><input type="hidden" name="trt" value="ajout"></td>
          </tr>
        </table>
      </form>
    </td>
  </tr>
</table>



Traitement :

  if( $_POST["trt"]=="ajout")
  {
    $nom="tmp";
    $resultat = move_uploaded_file($_FILES['fichier']['tmp_name'],"./upload/".$nom);
    if ($resultat) echo "Transfert réussi"; else echo "CHIER !!!!";

    echo "==>".$_FILES['fichier']['error']."<br>";
    echo "==>".$_FILES['fichier']['name']."<br>";
    $fp = fopen("./upload/".$nom,"r");
    $data = fread($fp,filesize($nom));
    fclose($fp);

    // Ajout enregistrement table mysql !
    $rqt="INSERT INTO `photos` ( `id` , `id_recettes` , `id_ingredients` , `photo` , `extension` , `alt`  )    VALUES (NULL , '".$_POST["id_recettes"]."', '', '".$data."', '".$_FILES['fichier']['type']."', '".addslashes($_POST["alt"])."' )";

    $r=mysql_query($rqt);
    if ($r!=0)
    {
      $id=mysql_insert_id();
      echo "Photo enregistree !!!";
    }
    else
    {
      echo $rqt;
    }
  }