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 :

Prévisualiser une image


Sujet :

Langage PHP

  1. #1
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Par défaut Prévisualiser une image
    Bonjour,

    J'aimerais pouvoir prévisualiser une image chargé depuis mon pc avant l'envoie vers la bdd.

    mais je n'arrive toujours pas.

    Code php : 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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml">
     
    <head>
      <title>News (add - preview)</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
     
    </head>
     
    <body>
    <?php
     
    if ($_POST) {
        @extract($_POST);
    }
     
    if (IsSet($_POST['add']))
     {
         $target_path = "uploads/";
         $target_path1 = $target_path . basename( $_FILES['fileupload']['name']);
         $target_path2 = $target_path . basename( $_FILES['imgupload']['name']);
     
         if(move_uploaded_file($_FILES['fileupload']['tmp_name'], $target_path1)) {
             $errimg = "The file ".  basename( $_FILES['fileupload']['name'])." has been uploaded";
        } else{
        $errimg .= "There was an error uploading the file, please try again!";
        }
     
        if(move_uploaded_file($_FILES['imgupload']['tmp_name'], $target_path2)) {
             $errimg .= "The file ".  basename( $_FILES['imgupload']['name'])." has been uploaded";
        } else{
        $errimg .= "There was an error uploading the file, please try again!";
        }
        echo $errimg;
     
         // do the insert here
         //$sql = 'INSERT INTO your_table ...';
         echo '<meta http-equiv="refresh" content="2; url=addnews.php" />';
         //header("Location: addnews.php");
    }
    elseif (IsSet($_POST['prev'])) {
    ?>
    <div style="display:block;">
        <p><b>Preview news</b></p>
        <p><?=$title;?></p>
        <div>
        <table style="flot:left; border : 1px solid #eee;">
            <tbody>
                <tr height="1"></tr>
                <tr>
                    <td width="1"></td>
                    <td align="center">
                        <img height="200" width="225" align="left" src="<?=$_FILES['fileupload']['tmp_name'];?>" alt="">
                        <img height="200" width="225" align="left" src="<?=$_FILES['linkupload']['tmp_name'];?>" alt="">
                    </td>
     
                </tr>
                <tr>
                    <td width="1"></td>
                    <td align="center"><font size="2" color="#333300"><?=$titleimg;?></font></td>
                    <td width="1"></td>
                    <td></td>
                </tr>
             </tbody>
        </table>
        </div>
        <span><?=$post;?></span>
        <br />
        <hr color="#0000FF" />
    </div>
    <?php
    }
    ?>
     
    <div style="display:block;">
    <form enctype="multipart/form-data" method="post" action="<?=$_SERVER['PHP_SELF']?>">
     
        <p>News title :
        <input type="text" name="title" value="<?=$title;?>" size="40" /></p>
        <p>Post :
        <textarea name="post" rows="10" COLS="40" ><?=$post?></textarea></p>
        <p>Image From PC :
        <input type="file" name="fileupload" /></p>
        <p>Image from link :
        <input type="text" name="linkupload" value="<?=$linkupload;?>"/></p>
        <p>Title of image :
        <input type="text" name="titleimg" value="<?=$titleimg;?>"/></p>
        <p>Title of image :
        <input name="add" type="submit" value="Inzert" />
        <input name="prev" type="submit" value="Preview" /></p>
     
    </form>
    </div>
    </body>
    </html>

    http://majallati.comli.com/test/preview/addnews.php

    Merci d'avance.

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Pourrais-tu décrire le problème que tu rencontres ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Par défaut
    les images n'apparait pas en cliquant le bouton preview.

  4. #4
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    serait-ce du à ça ?! :
    Avertissement

    N'utilisez pas extract() sur des données inconnues, comme les données utilisateurs (i.e. $_GET, $_FILES, etc.). Si vous le faites, par exemple, pour rendre compatible un vieux code avec register_globals à Off de façon temporaire, assurez-vous d'utiliser l'une des constantes extract_type qui n'écrasent pas les valeurs, comme EXTR_SKIP. Sachez aussi que vous devez maintenant extraire dans le même ordre que celui défini dans variables_order du php.ini.

  5. #5
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Par défaut
    Citation Envoyé par vorace Voir le message
    serait-ce du à ça ?! :
    Remplacé par :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    if ($_POST) {
        //@extract($_POST);
        $title = $_POST['title'];
        $post = $_POST['post'];
        $titleimg = $_POST['titleimg'];
    }

    le problème persiste toujours !!

  6. #6
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Tu ne peux pas lire une image temporaire, elle est détruite a la fin du script.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  7. #7
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Par défaut
    Citation Envoyé par sabotage Voir le message
    Tu ne peux pas lire une image temporaire, elle est détruite a la fin du script.
    Y'a-t-il une solution pour le faire ?

    par exemple la sauvegarder dans un dossier tempo puis l'effacer après aperçu du news+image ?

    ou une autre solutions fiable ?

  8. #8
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    par exemple la sauvegarder dans un dossier tempo puis l'effacer après aperçu du news+image ?
    oui !

  9. #9
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Par défaut
    Voila à nouveau le code :

    Ca marche seulement pour l'image chargé du PC.

    Et je sais pas si vu coté programmation le code est correct

    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml">
     
    <head>
      <title>News (add - preview)</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
     
    </head>
     
    <body>
    <?php
     
    if ($_POST) {
        //@extract($_POST);
        $title = $_POST['title'];
        $post = $_POST['post'];
        $titleimg = $_POST['titleimg'];
    }
     
    if (IsSet($_POST['add']))
     {
         $target_path = "uploads/";
         $target_path1 = $target_path . basename( $_FILES['fileupload']['name']);
         $target_path2 = $target_path . basename( $_FILES['linkupload']['name']);
     
         if(move_uploaded_file($_FILES['fileupload']['tmp_name'], $target_path1)) {
             $errimg = "The file ".  basename( $_FILES['fileupload']['name'])." has been uploaded";
        } else{
        $errimg .= "There was an error uploading the file, please try again!";
        }
     
        if(move_uploaded_file($_FILES['linkupload']['tmp_name'], $target_path2)) {
             $errimg .= "The file ".  basename( $_FILES['linkupload']['name'])." has been uploaded";
        } else{
        $errimg .= "There was an error uploading the file, please try again!";
        }
        echo $errimg;
     
         // do the insert here
         //$sql = 'INSERT INTO your_table ...';
         echo '<meta http-equiv="refresh" content="2; url=addnews.php" />';
         //header("Location: addnews.php");
    }
    elseif (IsSet($_POST['prev'])) {
     
     
     
         $target_temp_path = "tempo/";
         $target_temp_path1 = $target_path . basename( $_FILES['fileupload']['name']);
         $target_temp_path2 = $target_path . basename( $_FILES['linkupload']['name']);
     
         if(move_uploaded_file($_FILES['fileupload']['tmp_name'], $target_temp_path1)) {
             $errimg = "The file ".  basename( $_FILES['fileupload']['name'])." has been uploaded";
        } else{
        $errimg .= "There was an error uploading the file, please try again!";
        }
     
        if(move_uploaded_file($_FILES['linkupload']['tmp_name'], $target_temp_path2)) {
             $errimg .= "The file ".  basename( $_FILES['linkupload']['name'])." has been uploaded";
        } else{
        $errimg .= "There was an error uploading the file, please try again!";
        }
        echo $errimg;
     
    ?>
    <div style="display:block;">
        <p><b>Preview news</b></p>
        <p><?=$title;?></p>
        <div>
        <table style="flot:left; border : 1px solid #eee;">
            <tbody>
                <tr height="1"></tr>
                <tr>
                    <td width="1"></td>
                    <td align="center">
                        <img height="200" width="225" align="left" src="<?=$target_temp_path1;?>" alt="">
                        <img height="200" width="225" align="left" src="<?=$target_temp_path2;?>" alt="">
                    </td>
     
                </tr>
                <tr>
                    <td width="1"></td>
                    <td align="center"><font size="2" color="#333300"><?=$titleimg;?></font></td>
                    <td width="1"></td>
                    <td></td>
                </tr>
             </tbody>
        </table>
        </div>
        <span><?=$post;?></span>
        <br />
        <hr color="#0000FF" />
    </div>
    <?php
    unset($target_temp_path1);
    unset($target_temp_path2);
    }
    ?>
     
    <div style="display:block;">
    <form enctype="multipart/form-data" method="post" action="<?=$_SERVER['PHP_SELF']?>">
     
        <p>News title :
        <input type="text" name="title" value="<?=$title;?>" size="40" /></p>
        <p>Post :
        <textarea name="post" rows="10" COLS="40" ><?=$post?></textarea></p>
        <p>Image From PC :
        <input type="file" name="fileupload" /></p>
        <p>Image from link :
        <input type="text" name="linkupload" value="<?=$linkupload;?>"/></p>
        <p>Title of image :
        <input type="text" name="titleimg" value="<?=$titleimg;?>"/></p>
        <p>Title of image :
        <input name="add" type="submit" value="Insert" />
        <input name="prev" type="submit" value="Preview" /></p>
     
    </form>
    </div>
    </body>
    </html>

  10. #10
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    normal t'as un input de type "text" pour le lien :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
        <p>Image from link :
        <input type="text" name="linkupload" value="<?=$linkupload;?>"/></p>
    tu ne peux pas récupérer le chemin avec $_FILES...

  11. #11
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Par défaut
    Par exemple comment puis-je récuperer cette image depuis son lien, dans le dossier tempo sur mon site :

    http://fr.php.net/images/php.gif

  12. #12
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    voila le code dont je me sers (adapté avec tes variables) :
    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
    // L'url du fichier
    		// Le chemin de sauvegarde
    		$path = 'tempo/';
    		// On coupe le chemin
    		$exp = explode('/',$linkupload);
    		// On recup l'adresse du serveur
    		$serv = $exp[0].'//'.$exp[2];
    		// On recup le nom du fichier
    		$name = array_pop($exp);
    		// On genere le contexte (pour contourner les protections anti-leech)
    		$xcontext = stream_context_create(array("http"=>array("header"=>"Referer: ".$serv."\r\n")));
    		// On tente de recuperer l'image
    		$content = file_get_contents($linkupload,false,$xcontext);
    		if ($content === false) 
    		{
    			$erreur.="<br/>Impossible de récuperer l'image.<br/>";
    		}
    		// Sinon, si c'est bon, on sauvegarde le fichier
    		$test = file_put_contents($path.'/'.$name,$content);
    		if ($test === false) 
    		{
    			$erreur.="<br/><h4>Impossible de sauvegarder l'image.</h4><br/>";
    		}

  13. #13
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Par défaut
    Merci vorace.

    Je vais m'en servir ...

  14. #14
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Par défaut
    Voila ç nouveau le code.

    mais il y' un problème : les images ne sont pas uploader dans le dossier tempo mais dans le même emplacement que le fichier appelant qui est addnews.php.

    ou est l'erreur ?

    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
    139
    140
    141
    142
    143
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml">
     
    <head>
      <title>News (add - preview)</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
     
    </head>
     
    <body>
    <?php
     
    if ($_POST) {
     
        $title = $_POST['title'];
        $post = $_POST['post'];
        $titleimg = $_POST['titleimg'];
    	$linkupload = $_POST['linkupload'];
    }
     
    if (IsSet($_POST['add']))
     {
         $target_path = "uploads/";
         $target_path1 = $target_path . basename( $_FILES['fileupload']['name']);
     
     
         if(move_uploaded_file($_FILES['fileupload']['tmp_name'], $target_path1)) {
             $errimg = "The file ".  basename( $_FILES['fileupload']['name'])." has been uploaded";
        } else{
        $errimg .= "There was an error uploading the file, please try again!";
        }
     
        echo $errimg;
    	//-------------
     
    $url = $linkupload;
    // the path of save
    $path = 'uploads/';
     
    $exp = explode('/',$url);
     
    $serv = $exp[0].'//'.$exp[2];
    // the name of file
    $filename = array_pop($exp); 
    // 
    $xcontext = stream_context_create(array("http"=>array("header"=>"Referer: ".$serv."\r\n")));
     
    $content = file_get_contents($url,false,$xcontext);
    if ($content === false) {
    	echo "\nImpossible to get file.";
    	exit(1);
    }
     
    $test = file_put_contents($path.'/'.$filename,$content);
    if ($test === false) {
    	echo "\nImpossible to save the file.";
    	exit(1);
    }
    // All it's OK
    echo "\nSaving file successfull.";
    $target_temp_path2 = $path.'/'.$filename;
    //--------------
     
         // do the insert here
         //$sql = 'INSERT INTO your_table ...';
         echo '<meta http-equiv="refresh" content="2; url=addnews.php" />';
         //header("Location: addnews.php");
    }
    elseif (IsSet($_POST['prev'])) {
     
     
     
         $target_temp_path = "tempo/";
         $target_temp_path1 = $target_path . basename( $_FILES['fileupload']['name']);
     
     
         if(move_uploaded_file($_FILES['fileupload']['tmp_name'], $target_temp_path1)) {
             $errimg = "The file ".  basename( $_FILES['fileupload']['name'])." has been uploaded\n";
        } else{
        $errimg .= "There was an error uploading the file ".basename( $_FILES['fileupload']['name']).", please try again!\n";
        }
     
     
     
    ?>
    <div style="display:block;">
        <p><b>Preview news</b></p>
        <p><?=$title;?></p>
        <div>
        <table style="flot:left; border : 1px solid #eee;">
            <tbody>
                <tr height="1"></tr>
                <tr>
                    <td width="1"></td>
                    <td align="center">
                        <img height="200" width="225" align="left" src="<?=$target_temp_path1;?>" alt="">
                        <img height="200" width="225" align="left" src="<?=$linkupload;?>" alt="">
                    </td>
     
                </tr>
                <tr>
                    <td width="1"></td>
                    <td align="center"><font size="2" color="#333300"><?=$titleimg;?></font></td>
                    <td width="1"></td>
                    <td></td>
                </tr>
             </tbody>
        </table>
        </div>
        <span><?=$post;?></span>
        <br />
        <hr color="#0000FF" />
    </div>
    <?php
    unset($target_temp_path1);
     
     
    }
    ?>
     
    <div style="display:block;">
    <form enctype="multipart/form-data" method="post" action="<?=$_SERVER['PHP_SELF']?>">
     
        <p>News title :
        <input type="text" name="title" value="<?=$title;?>" size="40" /></p>
        <p>Post :
        <textarea name="post" rows="10" COLS="40" ><?=$post?></textarea></p>
        <p>Image From PC :
        <input type="file" name="fileupload" /></p>
        <p>Image from link :
        <input type="text" name="linkupload" value="<?=$linkupload;?>"/></p>
        <p>Title of image :
        <input type="text" name="titleimg" value="<?=$titleimg;?>"/></p>
        <p>Title of image :
        <input name="add" type="submit" value="Insert" />
        <input name="prev" type="submit" value="Preview" /></p>
     
    </form>
    </div>
    </body>
    </html>

  15. #15
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    ou se trouve tempo par rapport au script appelant ?

  16. #16
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867

  17. #17
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    quelles images ne sont pas sauvegardées au bon endroit ?
    celle avec le lien ou depuis le pc client?

  18. #18
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Par défaut
    L'image avec lien est prévisualiser directement avec son lien.

    mais l'image depuis le pc client n'est pas sauvegarder dans le dossier tempo ....

  19. #19
    apt
    apt est déconnecté
    Membre éclairé
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Par défaut
    il fallait ecrire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $target_temp_path1 = $target_temp_path . basename( $_FILES['fileupload']['name']);
    au lieu de :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $target_temp_path1 = $target_path . basename( $_FILES['fileupload']['name']);
    un autre probleme :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    unlink($target_temp_path1);
    à la fin de la prévisualisation me pose un soucis.

    l'image est supprimée et je ne peux la voir !!!?

    une solution ?

  20. #20
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    enlève le unlink, et au moment ou tu testes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(IsSet($_POST['add'])){....}
    à ce moment la tu testes si le fichier existe avec file_exists() dans tempo et si c'est le cas tu le déplaces dans uploads sans le supprimer mais au cas ou l'utilisateur change d'image entre la preview et la validation, tu crées une variable de session dans laquelle tu stocks le nom de l'image que tu supprimes si elle est différente de l'image validé...je sais c'est un peu compliqué dit comme ça mais je t'aurai bien fait le code pour que tu puisses voir mais la je suis débordé...

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. [AJAX] Prévisualiser une image avant le téléchargement
    Par zied.ellouze dans le forum AJAX
    Réponses: 0
    Dernier message: 19/10/2011, 13h04
  2. Prévisualisation d'une image
    Par Stefounette dans le forum JavaFX
    Réponses: 1
    Dernier message: 06/04/2010, 17h00
  3. Prévisualisation d'une image sélectionnée sur disque dur
    Par ero-sennin dans le forum Général JavaScript
    Réponses: 12
    Dernier message: 03/08/2008, 00h54
  4. Prévisualisation d'une image
    Par chris28200 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 08/08/2007, 17h01
  5. prévisualiser une image avant upload
    Par johan_b dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 26/01/2007, 21h42

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