Variable PHP du type $var via URL

Résolu
Bonjour a tous !

Ce n'est pas faute d'avoir essayé mais je tente de faire passer une variable via une URL mais ca ne marche pas... je vous donne quelques détails ?

Donc voila, j'ai une page qui s'appelle Admin.php et une autre qui se nomme upload.php

Dans Admin.php :
J'affecte $dossiercible avec un texte (du style <i>Vancances</i> ou <i>Photos du 31.06.07</i>...) puisque celui ci représente le nom d'un dossier qui comporte des photos...
Ensuite, un peu plus haut, j'ai :
<form name='MyForm' enctype='multipart/form-data' method='POST' action='upload.php?cible=photos&table=`photo`&dossier=".$dossiercible.">";

Mais le problème est la...je n'arrive pas a balancer via l'URL la variable $dossiercible dans la page upload.php (Pas d'inquiètude, j'ai testé, et $dossiercible est bien affecté de qqch...)

Dans upload.php :

Je récupère donc mes variables comme ceci :

$dossier = $_GET['dossier'];
$table = $_GET['table'];
$cible = $_POST['cible'];

echo $table; <i>(Ceci affiche bien `photo`)</i>
echo $cible; <i>(Ceci affiche bien photos)</i>
echo $dossier; <i>(Ceci n'affiche rien</i>

Donc voila mon problème, qqn serait il capable de me le résoudre...? Merci

NickoX9
Configuration: Windows XP
Internet Explorer 6.0

15 réponses

  1. Dans la ligne:

    <form name='MyForm' enctype='multipart/form-data' method='POST' action='upload.php?cible=photos&table=`photo`&dossier=".$dossiercible.">";

    la balise <form est du HTML, alors il faut que tu mettre entre les tags php les variables php !

    <form name='MyForm' enctype='multipart/form-data' method='POST' action='upload.php?cible=photos&table=`photo`&dossier="<?php echo $dossiercible" ?> >';
    1. Salut,

      En fait je pense que ton problème viens du fait que tu essais de faire passer des caractères <>/ et espace dans ton URL. A vérifier mais je crois pas que ça soit possible.
      Le plus simple pour le vérifié c'est d'affecter une chaine classique a ta variable (ex : "azerty")

      <form name='MyForm' enctype='multipart/form-data' method='POST' action='upload.php?cible=photos&table=`photo`&dossier=azerty>";
      1. Salut,

        En fait je pense que ton problème viens du fait que tu essais de faire passer des caractères <>/ et espace dans ton URL. A vérifier mais je crois pas que ça soit possible.
        Le plus simple pour le vérifié c'est d'affecter une chaine classique a ta variable (ex : "azerty")

        <form name='MyForm' enctype='multipart/form-data' method='POST' action='upload.php?cible=photos&table=`photo`&dossier=azerty>";
        1. bonjour,

          echo '<form name=\'MyForm\' enctype=\'multipart/form-data\' method=\'POST\' action=\'upload.php?cible=photos&table=photo&dossier='.$dossiercible.'\'>';

          comme ça, ça foncionne.
          1. Dans mon cas, cible doit être appelé

            $cible = $_GET['cible'];

            aussi.

            ... mon test :

            $dossiercible='test';
            echo '<form name=\'MyForm\' enctype=\'multipart/form-data\' method=\'POST\' action=\'upload.php?cible=photos&table=photo&dossier='.$dossiercible.'\'>';
            echo '<br/><br/><input accesskey=\'s\' type=\'submit\' value=\'envoyer\'/>';
            echo "</form>";
            1. En fait mon code c'est ca :

              <head><link href="style.css" rel="stylesheet" type="text/css"></head>
              <body bgcolor="black" alink="white" vlink="white" link="white" text="white" oncontextmenu="return false">
              <form name='MyForm' enctype='multipart/form-data' method='POST' action='upload.php?cible=photos&table=`photo`&dossier="<?php echo $dossiercible" ?> >';
              <?
              //SELECTION PHOTO
              //CHOIX DE LA PHOTO ET DE SON DOSSIER
              echo "<table width='50%' border='2' cellspacing='0' cellpadding='0'>";
              echo "<tr>";
              echo "<td><CENTER>";
              echo "<b>Photo</b><br><br>";
              echo "Titre : <input type='text' size='30' name='titre'><br>";
              echo "<input type='hidden' name='posted' value='1'/><br>
              <input name='fichier' type='file' size='30'><br><br>";

              ...et il me mets : Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in E:\Programmes\PortableZMWS\ZMWS\_web.zmwsc\Site\Perso\Admin.php on line 19

              La ligne 19 c'est :
              echo "<table width='50%' border='2' cellspacing='0' cellpadding='0'>";

              Merci Alain42

              NickoX9
              1. Tu as oublié le ; au dessus à la ligne précédente, je pense... ici : echo $dossiercible;

                ... utilise ce que je t'ai mis plus haut, ça fonctionne.
                1. <form name='MyForm' enctype='multipart/form-data' method='POST' action='upload.php?cible=photos&table=`photo`&dossier="<?php echo $dossiercible" ?> >';

                  Apparement tu n'est pas en php la donc il faut enlever le '; a la fin de cette ligne et il y a un pb avec les double cotes. Ca doit etre mieux comme ca

                  <form name='MyForm' enctype='multipart/form-data' method='POST' action='upload.php?cible=photos&table=`photo`&dossier=<?php echo $dossiercible ?>' >

                  1. <form name='MyForm' enctype='multipart/form-data' method='POST' action='upload.php?cible=photos&table=`photo`&dossier=<?php echo $dossiercible ?>' >

                    et le ; à la fin de $dossiercible ???
                  2. @Viktor56Quand il n'y a qu'une seule ligne de php je sais plus si il est obligatoire mais oui tu as raison c'est plus prudent de le mettre
                2. Testé et approuvé

                  <?php

                  $dossiercible = "monDosier"

                  ?>

                  <html>
                  <head><link href="style.css" rel="stylesheet" type="text/css"></head>
                  <body bgcolor="black" alink="white" vlink="white" link="white" text="white" >
                  <form name='MyForm' enctype='multipart/form-data' method='POST' action='upload.php?cible=photos&table=photo&dossier=<?php echo $dossiercible ?>' >
                  <?php
                  //SELECTION PHOTO
                  //CHOIX DE LA PHOTO ET DE SON DOSSIER
                  echo "<table width='50%' border='2' cellspacing='0' cellpadding='0'>";
                  echo "<tr>";
                  echo "<td><CENTER>";
                  echo "<b>Photo</b><br><br>";
                  echo "Titre : <input type='text' size='30' name='titre'><br>";
                  echo "<input type='hidden' name='posted' value='1'/><br><input name='fichier' type='file' size='30'><br><br>";
                  ?>
                  </form>

                  </html>
                  1. Ca ne marche pas... je vous mets chaque page ///

                    Admin.php :

                    <? include "connexion.php"; ?>

                    <script language="javascript"> ///FONCTION QUI PERMET LA CREATION DE NOUVEAUX CHAMPS DANS LE TABLEAU`
                    function creer(val){ ///PERMET DE GRISER LE MENU DEROULANT OU LES "RADIO BUTTON"
                    if (val == "dossier")
                    {
                    document.MyForm.NEWdossier.type='text';
                    document.MyForm.dossier.disabled="disabled";
                    }
                    }
                    </script>
                    <head><link href="style.css" rel="stylesheet" type="text/css"></head>
                    <body bgcolor="black" alink="white" vlink="white" link="white" text="white" oncontextmenu="return false">
                    <?
                    //SELECTION PHOTO
                    //CHOIX DE LA PHOTO ET DE SON DOSSIER action='Admin.php'
                    echo '<form name=\'MyForm\' enctype=\'multipart/form-data\' method=\'POST\' action=\'upload.php?cible=photos&table=photo&dossier='.$dossiercible.'\'>';
                    echo "<table width='50%' border='2' cellspacing='0' cellpadding='0'>";
                    echo "<tr>";
                    echo "<td><CENTER>";
                    echo "<b>Photo</b><br><br>";
                    echo "Titre : <input type='text' size='30' name='titre'><br>";
                    echo "<input type='hidden' name='posted' value='1'/><br>
                    <input name='fichier' type='file' size='30'><br><br>";

                    //SELECTION DOSSIER
                    $query="select DISTINCT * from photo order by dossier;";
                    echo " <b>Dossier(s) : </b> <a href=\"javascript:creer('dossier');\">
                    Créer un dossier</a>  <input type='hidden' name='NEWdossier' size='20'>
                    <br>
                    <select name='dossier' align='left'><option VALUE='0'>Choisir un dossier</option>";
                    if($p= mysql_query($query,$bd))
                    {
                    while($Tab = mysql_fetch_array($p))
                    {
                    echo "<option value='".$Tab["dossier"]."'>".$Tab["dossier"]."</option>"."<br>";
                    }
                    }
                    echo "</select><br><br>";

                    $titre = $_POST['titre'];
                    $cible = "photos";
                    $table = "`photo`";

                    if(!empty ($_POST['NEWdossier']))
                    {
                    $newdossier = $_POST['NEWdossier'];
                    $dossiercible = $newdossier;
                    //mkdir($cible."/".$NEWdossier, 0777);
                    }
                    else
                    {
                    $dossier = $_POST['dossier'];
                    $dossiercible = $dossier;
                    }
                    echo "<input type='submit' value='Ajouter la photo !'
                    style='font-family: Arial,Verdana,Helvetica;
                    font-size: 13px;
                    color:#ffffff ;
                    background-color: black;
                    width:150px;'></CENTER>";
                    ?>
                    </form>
                    </body>
                    </html>

                    upload.php :

                    <? include "connexion.php"; ?>
                    <html>
                    <head>
                    <link href="style.css" rel="stylesheet" type="text/css">
                    </head>
                    <body bgcolor="black" alink="white" vlink="white" link="white" text="white" oncontextmenu="return false">

                    <?

                    $cible = $_GET['cible'];
                    $dossier = $_GET['dossier'];
                    $table = $_GET['table'];
                    $titre = $_POST['titre'];

                    echo "Table utilisée :".$table."<br>";
                    echo "titre : ".$titre."<br>";
                    echo "Nom du sous dossier : ".$dossier."<br>";
                    echo "Nom du dossier général : ".$cible."<br><br><br><br><br><br>";
                    ?>
                    </body>
                    </html>

                    Voila, je ne c pa pourquoi chez vous ca fonctionne mais pas chez moi...

                    Merci beaucoup...

                    Nicko
                    1. hum ... ok En fait tu écris ton URL avant d'affecter ta variable dans Admin.php
                      1. Voila j'ai pas changer grand chose mais au moins ta variable est passé

                        Admin.php
                        <Html>
                        <script language="javascript"> ///FONCTION QUI PERMET LA CREATION DE NOUVEAUX CHAMPS DANS LE TABLEAU`
                        function creer(val){ ///PERMET DE GRISER LE MENU DEROULANT OU LES "RADIO BUTTON"
                        if (val == "dossier")
                        {
                        document.MyForm.NEWdossier.type='text';
                        document.MyForm.dossier.disabled="disabled";
                        }
                        }
                        </script>
                        <head><link href="style.css" rel="stylesheet" type="text/css"></head>
                        <body bgcolor="black" alink="white" vlink="white" link="white" text="white" oncontextmenu="return false">
                        <?php
                        //SELECTION PHOTO
                        //CHOIX DE LA PHOTO ET DE SON DOSSIER action='Admin.php'
                        echo '<form name=\'MyForm\' enctype=\'multipart/form-data\' method=\'POST\' action=\'upload.php?cible=photos&table=photo&dossier='.$dossiercible.'\'>';
                        echo "<table width='50%' border='2' cellspacing='0' cellpadding='0'>";
                        echo "<tr>";
                        echo "<td><CENTER>";
                        echo "<b>Photo</b><br><br>";
                        echo "Titre : <input type='text' size='30' name='titre'><br>";
                        echo "<input type='hidden' name='posted' value='1'/><br>
                        <input name='fichier' type='file' size='30'><br><br>";
                        
                        //SELECTION DOSSIER
                        $query="select DISTINCT * from photo order by dossier;";
                        echo " <b>Dossier(s) : </b> <a href=\"javascript:creer('dossier');\">
                        Créer un dossier</a>  <input type='hidden' name='NEWdossier' size='20'>
                        <br>
                        <select name='dossier' align='left'><option VALUE='0'>Choisir un dossier</option>";
                        if($p= mysql_query($query,$bd))
                        {
                        while($Tab = mysql_fetch_array($p))
                        {
                        echo "<option value='".$Tab["dossier"]."'>".$Tab["dossier"]."</option>"."<br>";
                        }
                        }
                        echo "</select><br><br>";
                        
                        
                        
                        $titre = $_POST['titre'];
                        $cible = "photos";
                        $table = "`photo`";
                        
                        if(!empty ($_POST['NEWdossier']))
                        {
                        $newdossier = $_POST['NEWdossier'];
                        $dossiercible = $newdossier;
                        //mkdir($cible."/".$NEWdossier, 0777);
                        }
                        else
                        {
                        $dossier = $_POST['dossier'];
                        $dossiercible = $dossier;
                        }
                        echo "<input type='submit' value='Ajouter la photo !'
                        style='font-family: Arial,Verdana,Helvetica;
                        font-size: 13px;
                        color:#ffffff ;
                        background-color: black;
                        width:150px;'></CENTER>";
                        ?>
                        </form>
                        </body>
                        </html> 
                        


                        Upload.php
                        <html>
                        <head>
                        <link href="style.css" rel="stylesheet" type="text/css">
                        </head>
                        <body bgcolor="black" alink="white" vlink="white" link="white" text="white" oncontextmenu="return false">
                        
                        <?php
                        
                        
                        $cible = $_GET['cible'];
                        if(isset($_POST['NEWdossier']))
                          $dossier = $_POST['NEWdossier'];
                        else
                          $dossier = $_POST['dossier'];
                        $table = $_GET['table'];
                        $titre = $_POST['titre'];
                        
                        echo "Table utilisée :".$table."<br>";
                        echo "titre : ".$titre."<br>";
                        echo "Nom du sous dossier : ".$dossier."<br>";
                        echo "Nom du dossier général : ".$cible."<br><br><br><br><br><br>";
                        ?>
                        </body>
                        </html> 
                        
                        1. Merci ca marche nickel !!!

                          Mais j'ai encore un souci (tant qu'on y est , autant en profiter...lol) , en fait, j'ai rajouté ce code d'upload de fichier (Pour mes photos) et il me dit :
                          Fatal error: Maximum execution time of 30 seconds exceeded in E:\Programmes\PortableZMWS\ZMWS\_web.zmwsc\Site\Perso\upload.php on line 63

                          En fait il m'insere bien ma photo dans le dossier et sous dossier souhaité mais il ne m'execute pas la requete (que j'ai mise en gras)

                          $target = $cible."/".$dossier ; // Repertoire cible
                          //echo $target." : Dossier target<br>";
                          $max_size = 1000000000; // Taille max en octets du fichier
                          $width_max = 10000; // Largeur max de l'image en pixels
                          $height_max = 10000; // Hauteur max de l'image en pixels

                          $nom_file = $_FILES['fichier']['name'];
                          $taille = $_FILES['fichier']['size'];
                          $tmp = $_FILES['fichier']['tmp_name'];
                          $error = $_FILES['fichier']['error'];

                          echo $nom_file." : nom file<br>";
                          echo $taille." : taille<br>";
                          echo $tmp." : tmp<br>";

                          //PERMET DE RECUPERER L'EXTENSION DU FICHIER
                          $extension=strrchr($nom_file,'.');
                          echo $extension." : Extension<br>";
                          $newfile=date("ymdHis").$extension; //CREATION D'UN NOUVEAU NOM POUR EVITER TT CONFLIT
                          echo $newfile." : nouveau nom<br>";

                          if(!empty($_POST['posted'])) {
                          if(!empty($nom_file)) { // VERIFICATION REMPLISSAGE CHAMP
                          $infos_img = getimagesize($tmp);// RECUPERATION DIMENSION
                          if(($infos_img[0] <= $width_max) && ($infos_img[1] <= $height_max) && ($taille <= $max_size)) { // VERIFICATION DIMENSION ET TAILLE
                          if(move_uploaded_file($tmp,$target."/".$newfile)) { echo "upload OK<BR>";// TEST UPLOAD
                          } else {echo '<b>Problème lors de l\'ajout !</b><br /><br /><b>', $error, '</b><br /><br />';}// ERREUR !
                          } else {echo '<b>Problème dans les dimensions ou taille de l\'image !</b><br /><br />';}// ERREUR DIMENSION ET TAILLE
                          } else {echo "<b>Le champ de selection de votre photo n'est pas rempli !</b>";}
                          }

                          //REQUETE D'INSERTION DANS LA TABLE
                          $query="INSERT INTO $table(`chemin`,`titre`,`dossier`)
                          VALUES ('".$target."/".$newfile."', '$titre', '$dossier' )";

                          echo $query." : Requete insertion <br>";
                          mysql_query($query);///EXECUTION DE LA REQUETE AJOUT
                          //header("Location: Admin.php"); ///REDIRECTION AUTOMATIQUE

                          ?>
                          </body>
                          </html>

                          rE mErCi !!!

                          NickoX9
                          1. Désolé j'ai oublié de mettre en gras la requete ... je vous l'écrit ici :

                            //REQUETE D'INSERTION DANS LA TABLE
                            $query="INSERT INTO $table(`chemin`,`titre`,`dossier`)
                            VALUES ('".$target."/".$newfile."', '$titre', '$dossier' )";


                            Voila... NickoX9
                            1. La ligne 63 c'est laquelle ?
                              move_uploaded_file($tmp,$target."/".$newfile)) 

                              Perso j'utilise la fonction 'rename' mais je sais pas du tout si ca viens de ça

                              Et sinon je remarque que ta requête se trouve en dehors de tout bloc 'if' C'est normal ?